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.

1
  • Please create a minimal demonstrative code. How to Ask Commented Jun 13, 2015 at 15:11

1 Answer 1

1
>>> np.where((conditions ==  a).all(axis=1))[0]
array([2])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.