[Numpy-discussion] Array search considering order

Oscar Benjamin oscar.j.benjamin at gmail.com
Fri Dec 20 06:19:49 EST 2013


On 19 December 2013 16:49, Andrei Rozanski <andrei at ruivo.org> wrote:
>
> Sorry if I was not clear enough.
> The SO question is alike what I want. However, in my problem, Im not sure if there will be only one occurence.
> What I do expect is:
> Given one array (big one), to retrieve indexes for "query array" occurences.
> Something like that:
>
> array1(big one) - 1,2,3,4,5,6,7,1,2,3,4,5,7,8,9,1,2,3,4,5,6,7,8
> array2(query) - 1,2,3
> array3(another query) - 8,7,6
>
> result (array1 versus array2) - 0,7,15 (position for match)
> result (array1 versus array3) - no matches

If you look more closely at the SO question you'll see that it does
answer your problem. The top-rated answer shows how to get an boolean
array indicating where the matches are. In your case that would be

[True, False, False, False, False, False, False, True, False, False,
False, False, False, False, False, True, False, False, False, False,
False]

Now just use the numpy.where function to get the indices of the True
value from this array.


Oscar



More information about the NumPy-Discussion mailing list