I have a large numpy array (dtype=int
) and a set of numbers which I\'d like to find in that array, e.g.,
import numpy as np
values = np.array(
I would say using np.in1d would be the intuitive solution to solve such a case. Having said that, based on this solution here's an alternative with np.searchsorted -
sidx = np.argsort(searchvals)
left_idx = np.searchsorted(searchvals,values,sorter=sidx,side='left')
right_idx = np.searchsorted(searchvals,values,sorter=sidx,side='right')
out = np.where(left_idx != right_idx)[0]