I have one (very long) boolean array a with k True entries, and one boolean array b of length k. I would like to get a boolean array c that is True if and only if a "and" b are True:
import numpy
a = numpy.array([False, False, True, False, True, False])
b = numpy.array([True, False])
assert numpy.sum(a) == len(b) # guaranteed
c = numpy.zeros(len(a), dtype=bool)
idx_b = 0
for k in range(len(a)):
if a[k]:
if b[idx_b]:
c[k] = True
idx_b += 1
print(c)
[False False True False False False]
This here uses a loop, but I'm thinking there must a faster way with boolean indexing, but I can't quite get to it.
Any hints?