Index of an array from a 2d np.array in Python?

190 Views Asked by At

i have a problem with find a index from a 2d np.array(). With an If-loop the computing time is too high for my algorithm. I need a numpy func to find the index from any array. The function np.where() doesn’t help me.. This is an abstraction:

>>> conditions = [[0 0 0 0 4]
[0 0 0 0 3]
[0 0 0 0 2]
..., 
[2 1 3 4 2]
[2 1 3 4 1]
[2 1 3 4 0]]
>>> a = [0, 0, 0, 0, 2]
>>> index = np.where(conditions==a)

If I use it so, although I have the column and row indices, but I can not interpret them. I need the concrete index value, for example index = 2.

1

There are 1 best solutions below

0
On BEST ANSWER
>>> np.where((conditions ==  a).all(axis=1))[0]
array([2])