On Thu, Dec 19, 2013 at 01:51:30PM +0000, Oscar Benjamin wrote: > Date: Thu, 19 Dec 2013 13:51:30 +0000 > From: Oscar Benjamin <oscar.j.benja...@gmail.com> > To: Discussion of Numerical Python <numpy-discussion@scipy.org> > Subject: Re: [Numpy-discussion] Array search considering order > > On 19 December 2013 12:51, rootspin <and...@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 > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion
Thank you Oscar for your answer. 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 Thanks for the help. _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion