I am trying to figure out an elegant way to make a combined mask between two arrays of different size with numpy
, but that the mask of one corresponds to the elements of the mask that have passed the large mask. To understand this well I put an example:
We have two mask arrays (understanding that 1 is True and 0 is False):
a = [0,1,1,1,0,1]
b = [0,0,1,0]
With b being the 4 elements corresponding to the 1s of a, so the result of this should be:
c = [0,0,0,1,0,0]
I keep thinking that there must be some native numpy operation that I must be missing or something, so I'd appreciate some help with this.
CodePudding user response:
This works:
a = np.array([0,1,1,1,0,1])
b = np.array([0,0,1,0])
c = a.copy()
c[c == True] = b