How using numpy, given a larger a and a smaller boolean array b
a = np.array([False, True, True, False, True])
b = np.array([False, True, False])
obtain the result c?
c = np.array([False, False, True, False, False])
That is to do the boolean and between b the part of a which is True to obtain the array c of the same shape as a? The number of elements that are True in the array a and the length of the array b does match.
>Solution :
How about this:
c = np.copy(a)
c[a] = b
First, c is created by copying a. Now, a, which is a boolean array, is used to select the elements of c where a is True.
Since a boolean and between some value and True is the value itself, boolean and between the array b and those elements of a that are True is simply the array b itself.
Finally, because the number of True elements of a is the same as the length of b, the assignment c[a] = b is possible.