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

Mark.Miller mpmusu@cc.usu....
Tue Aug 21 09:23:30 CDT 2007


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, 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 )
>>>> where(row==True)
> (array([2]),)
> 


More information about the Numpy-discussion mailing list