1

I want to find a 2d array in a 3d array. for finding a 1d array in a 2d array I can use np.where(np.all(a==b, axis=1))[0][0].

>>> import numpy as np
>>>
>>> a = np.array([[[1, 0, 0],
                   [0, 0, 0],
                   [0, 0, 0]],

                  [[0, 0, 0],
                   [0, 0, 0],
                   [0, 0, 0]]])
>>>
>>> b = np.array([[1, 0, 0],
                  [0, 0, 0],
                  [0, 0, 0]])
>>>
>>> a.find(b)
0
1
  • It's almost the same. You just need to use the proper axis and maybe use another all method. Commented Apr 1, 2018 at 8:14

1 Answer 1

6

The axis keyword accepts tuples, so you can simply do:

np.where(np.all(a==b, axis=(1, 2)))[0][0]
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.