[Numpy-discussion] [Newbie] Matching a subarray
oliphant at ee.byu.edu
Wed Jan 25 11:41:08 CST 2006
Dani Marti wrote:
>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.
More information about the Numpy-discussion