This seems like a simple thing to do but I could not figure it out...
first = np.array([0,1,2,0,4,2])
second = np.array([1,2])
I'd like to do element-wise comparison so that the answer will be
array([False, True, True, False, False, True], dtype=bool)
Basically I want it to say True
for each of the elements in first
which is also in second
. So if first
has 100 elements, then the output should have 100 elements, too.
But I can't figure out how. I've tried using np.equal
, np.any
, first==np.any(second)
to no avail. Of course, I can write a loop to do this but I know there must be a way to do this relatively simple task!