0

I have a numpy 2D array,

import numpy as np
array1 = array([[ 1,  2,  1,  1],
   [ 2,  2,  2,  1],
   [ 1,  1,  1,  1],
   [1,  3, 1, 1],
   [1,  1, 1, 1]])

I would like to find the element '3' and know its location. So, I could try

condition = array1 == 3

and then to find the arguments, I could try

np.argwhere(condition)

How else does one locate the indices where 3 is located?

1 Answer 1

1

You can also use where, returning a tuple of coordinate:

In [34]: np.where(array1==3)
Out[34]: (array([3]), array([1]))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.