[Numpy-discussion] Array search considering order

Oscar Benjamin oscar.j.benjamin at gmail.com
Thu Dec 19 08:51:30 EST 2013


On 19 December 2013 12:51, rootspin <andrei at ruivo.org> wrote:
> Hello,
>
> Need some help in searching arrays (Im new to numpy)
> Is it possible to search a array, using another array considering
> order/sequence?
>
> x = np.array([1,2,3,4,5,6], np.int32)
>
> y = np.array([1,4,3,2,6,5], np.int32)
>
> query= np.array([1,2,3],np.int32)
>
> x versus query True
> y versus query False
>
>
> Tried with:
>
> np.searchsorted(x,query)  -------> array([0, 1, 2])
> np.searchsorted(y,query)  -------> array([0, 1, 4])

I'm not sure if I understand your problem do you mean that you want to
find subarrays of an array the same way that e.g. "in" for strings
tests for substrings:

>>> 'asd' in 'qweasdzxc'
True

If so then perhaps this SO question has the answer you want:
http://stackoverflow.com/questions/7100242/python-numpy-first-occurrence-of-subarray


Oscar



More information about the NumPy-Discussion mailing list