2

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.

Robi Roboter
  • 43
  • 1
  • 7

1 Answers1

1
>>> np.where((conditions ==  a).all(axis=1))[0]
array([2])
behzad.nouri
  • 74,723
  • 18
  • 126
  • 124