Re: [Numpy-discussion] Finding a row match within a numpy array

2007-08-21 Thread Mark.Miller
A slightly related question on this topic... Is there a good loopless way to identify all of the unique rows in an array? Something like numpy.unique() is ideal, but capable of extracting unique subarrays along an axis. Thanks, -Mark mark wrote: > Maybe this is not the intended use of where,

Re: [Numpy-discussion] Finding a row match within a numpy array

2007-08-18 Thread Stefan van der Walt
On Tue, Aug 14, 2007 at 11:53:03AM +0100, Andy Cheesman wrote: > Dear nice people > > I'm trying to match a row (b) within a large numpy array (a). My most > successful attempt is below > > hit = equal(b, a) > total_hits = add.reduce(hit, 1) > max_hit = argmax(total_hits, 0) > answer = a[max_hit]

Re: [Numpy-discussion] Finding a row match within a numpy array

2007-08-18 Thread Stefan van der Walt
On Tue, Aug 14, 2007 at 11:53:03AM +0100, Andy Cheesman wrote: > Dear nice people > > I'm trying to match a row (b) within a large numpy array (a). My most > successful attempt is below > > hit = equal(b, a) > total_hits = add.reduce(hit, 1) > max_hit = argmax(total_hits, 0) > answer = a[max_hit]

[Numpy-discussion] Finding a row match within a numpy array

2007-08-16 Thread Andy Cheesman
Dear nice people I'm trying to match a row (b) within a large numpy array (a). My most successful attempt is below hit = equal(b, a) total_hits = add.reduce(hit, 1) max_hit = argmax(total_hits, 0) answer = a[max_hit] where ... a = array([[ 0, 1, 2, 3], [ 4, 5, 6, 7],

Re: [Numpy-discussion] Finding a row match within a numpy array

2007-08-15 Thread mark
Maybe this is not the intended use of where, but it seems to work: >>> from numpy import * # No complaining now >>> a = arange(12) >>> a.shape = (4,3) >>> a array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) >>> b = array([6,7,8]) >>> row = all( equal(a,b), 1 ) >>>

Re: [Numpy-discussion] Finding a row match within a numpy array

2007-08-15 Thread Matthieu Brucher
The where function ? Matthieu 2007/8/15, mark <[EMAIL PROTECTED]>: > > Oops, 'find' is in pylab (matplotlib). > I guess in numpy you have to use 'where', which does almost the same, > but it returns a Tuple. > Is there a function that is more like the find in matplotlib? > Mark > > > On Aug 15, 1

Re: [Numpy-discussion] Finding a row match within a numpy array

2007-08-15 Thread mark
Oops, 'find' is in pylab (matplotlib). I guess in numpy you have to use 'where', which does almost the same, but it returns a Tuple. Is there a function that is more like the find in matplotlib? Mark On Aug 15, 12:26 pm, Andy Cheesman <[EMAIL PROTECTED]> wrote: > Thanks for the speedy response bu

Re: [Numpy-discussion] Finding a row match within a numpy array

2007-08-15 Thread Andy Cheesman
Thanks for the speedy response but where can I locate the find function as it isn't in numpy. Andy mark wrote: > I think you can create an array with a true value in the right spot as > folows: > > row = all( equal(a,b), 1 ) > > Then you can either find the row (but you already knew that one, a

Re: [Numpy-discussion] Finding a row match within a numpy array

2007-08-15 Thread mark
I think you can create an array with a true value in the right spot as folows: row = all( equal(a,b), 1 ) Then you can either find the row (but you already knew that one, as it is b) a[row] or the row index find(row==True) Mark On Aug 15, 11:53 am, Andy Cheesman <[EMAIL PROTECTED]> wrote: >

[Numpy-discussion] Finding a row match within a numpy array

2007-08-15 Thread Andy Cheesman
Dear nice people I'm trying to match a row (b) within a large numpy array (a). My most successful attempt is below hit = equal(b, a) total_hits = add.reduce(hit, 1) max_hit = argmax(total_hits, 0) answer = a[max_hit] where ... a = array([[ 0, 1, 2, 3], [ 4, 5, 6, 7],