[Numpy-discussion] [Newbie] Matching a subarray
Travis Oliphant
oliphant at ee.byu.edu
Wed Jan 25 11:41:08 EST 2006
Dani Marti wrote:
>Hi all,
>
>I have a long 1D boolean array. I'd like to know where a certain
>'sub'array (like, e.g., ([1,1,1,1,1,1])) occurs in the array. That is, I
>want the index of the first occurrence of a subarray in an array,
>avoiding the use of explicit loop structures to carry out the search.
>
>
Actually, I don't think that's a trivial question. You could look at
the data as a string and use the find method of the string.
Or you could use (int8) correlation. The largest value of the
correlation should be the index where it matches.
-Travis
More information about the NumPy-Discussion
mailing list