1

Looking into this related question:

Numpy Array Get row index searching by a row

I would like to know if there is a method without loops that would return an array of indexes of where each row of array y is located within array x.

Here is an example:

x= np.array([[0,1],[0,2],[0,3],[1,1],[1,2],[1,3],[2,1],[2,2],[2,3]])
y = np.array([[0,1],[0,3],[1,1],[2,1],[2,2],[2,3]])

The desired output should be:

[0,2,3,6,7,8]

y array will never have any duplicates, and all elements of y will be located within x. Since I am working with big arrays (in the order millions of elements), using any loop solution is not feasible. This is the reason why I am looking for a "numpy command", if it exists, that does the trick.

Dominik
  • 1,016
  • 11
  • 30
  • 1
    Using `%%timeit` with an array of 60 elements and a subarray of 12 elements, approach 1 gives 76.1 µs ± 561 ns per loop, approach 2 gives 84.4 µs ± 2.42 µs per loop and approach 3 gives 54.1 µs ± 548 ns per loop. – Alex Martínez Ascensión Sep 20 '18 at 09:00

0 Answers0