I am looking for a numpy function to find the indices at which certain values are found within a vector (xs). The values are given in another array (ys). The returned indice
For big arrays xs
and ys
, you would need to change the basic approach for this to become fast. If you are fine with sorting xs
, then an easy option is to use numpy.searchsorted()
:
xs.sort()
ndx = numpy.searchsorted(xs, ys)
If it is important to keep the original order of xs
, you can use this approach, too, but you need to remember the original indices:
orig_indices = xs.argsort()
ndx = orig_indices[numpy.searchsorted(xs[orig_indices], ys)]