[Numpy-discussion] lexsort
Eleanor
e.howick at irl.cri.nz
Tue May 6 21:14:59 EDT 2008
Anne Archibald <peridot.faceted <at> gmail.com> writes:
>
> It appears that lexsort is broken in several ways, and its docstring
> is misleading.
>
> First of all, this code is not doing quite what you describe. The
> primary key here is the [5,6,7,8] column, followed by the middle and
> then by the first. This is almost exactly the opposite of what you
> want.
Ouch!
That would've got me bad.
>>>a = numpy.array([[1,2,60], [2,2,800], [2,1,7],[1,1,50]])
>>> a
array([[ 1, 2, 60],
[ 2, 2, 800],
[ 2, 1, 7],
[ 1, 1, 50]])
>>> a[numpy.lexsort( (a[:,1],a[:,0]) ),:]
array([[ 1, 1, 50],
[ 1, 2, 60],
[ 2, 1, 7],
[ 2, 2, 800]])
This is correct
versus
>>> a[numpy.lexsort(a.T),:]
array([[ 2, 1, 7],
[ 1, 1, 50],
[ 1, 2, 60],
[ 2, 2, 800]])
which isn't.
Thanks very much Eleanor
More information about the NumPy-Discussion
mailing list