I want to suggest one-line solution:
indices = np.where(np.in1d(x, y))[0]
The result is an array with indices for x array which corresponds to elements from y which were found in x.
One can use it without numpy.where if needs.
More Related Contents:
- Get the position of the largest value in a multi-dimensional NumPy array
- Generalise slicing operation in a NumPy array
- Numpy sub-array assignment with advanced, mixed indexing
- How is numpy’s fancy indexing implemented?
- Access n-th dimension in python [duplicate]
- Is there a NumPy function to return the first index of something in an array?
- Understanding NumPy’s einsum
- Intuition and idea behind reshaping 4D array to 2D array in NumPy
- Is there any numpy group by function?
- Computing the correlation coefficient between two multi-dimensional arrays
- Removing nan values from an array
- Why is numpy’s einsum faster than numpy’s built in functions?
- How to return 0 with divide by zero
- Reshape an array in NumPy
- Interweaving two numpy arrays
- Most efficient way to forward-fill NaN values in numpy array
- NumPy array initialization (fill with identical values)
- Why does numpy.zeros takes up little space
- Selecting Random Windows from Multidimensional Numpy Array Rows
- Searching a sequence in a NumPy array
- How to split a numpy array in fixed size chunks with and without overlap?
- Parameters to numpy’s fromfunction
- List to array conversion to use ravel() function
- Initialise numpy array of unknown length
- Efficient distance calculation between N points and a reference in numpy/scipy
- Index all *except* one item in python
- Why does numpy.linalg.solve() offer more precise matrix inversions than numpy.linalg.inv()?
- load csv into 2D matrix with numpy for plotting
- Convert list of lists with different lengths to a numpy array [duplicate]
- Select elements of numpy array via boolean mask array