I have three numpy arrays, one the source array, one destination array and one mask array. I want to replace the values in the destination with the same values from the source only at the places where the mask is equal to one.
My naiive try was:
import numpy as np
destination = np.arange(9).reshape((3,3))
source = np.ones((3,3))
mask = np.zeros((3,3)).astype(np.uint8)
mask[1,1]=1
destination[mask] = source[mask]
which leads me to destination being
[[1, 1, 1],
[1, 1, 1],
[6, 7, 8]]
whereas I expect it to be
[[0, 1, 2],
[3, 1, 5],
[6, 7, 8]].
I do get the correct result, when I do
destination[mask==1] = source[mask==1].
My question is: Why are these two commands not identical, or what does the first even do?
np.uint8for a mask? Shouldn't that be a boolean array?source[mask]is giving you