I am trying to use numpy.where
to find the indices I want. Here's the code:
import numpy as np
a = np.array([20,58,32,0,107,57]).reshape(2,3)
item_index = np.where((a == 58) | (a == 107) | (a == 20))
print item_index
I get item_index
as below:
(array([0, 0, 1]), array([0, 1, 1]))
However, in reality, the dimensions of a
is 20000 x 7
and the conditions are several hundred instead of just three. Is there a way to use numpy.where
for multiple conditions? I found topics here, here and here useful, but I couldn't find the answer to my question.
where
. The problem you're having is efficiently compressing several hundred equality conditions into one short, efficient condition.where
at all and mostly usednp.in1d