Find the index position of all elements within an array with matching values from a test array in numpy

  numpy, python

I have a numpy array like:

a = np.array([[1, 2, 3, 456], [2, 3, 4, 789], [3, 4, 5, 101112], [4, 5, 6, 131415]])

I have an array of numbers like:

b = np.array([101112, 456])

I am looking for:

[2, 0]

How can I get the index positions in a using b?

Currently, I am using a nested loop which is highly inefficient.

I cannot get np.where to do this, at least with my limited understanding.

Source: Python Questions

LEAVE A COMMENT