[Numpy-discussion] lexsort

Charles R Harris charlesr.harris at gmail.com
Tue May 2 21:12:05 EDT 2006


Hi,

On 5/2/06, Francesc Altet <faltet at carabos.com> wrote:
>
> A Dimarts 02 Maig 2006 19:36, Charles R Harris va escriure:
> > Francesc,
> >
> > Completely off topic, but are you aware of the lexsort function in numpy
> > and numarray? It is like argsort but takes a list of (vector)keys and
> > performs a stable sort on each key in turn, so for record arrays you can
> > get the effect of sorting on column A, then column B, etc. I thought I
> > would mention it because you seem to use argsort a lot and, well,
> because I
> > wrote it ;)
>
> Thanks for pointing this out. In fact, I had no idea of this
> capability in numarray (numpy neither). I'll have to look more
> carefully into this to fully realize the kind of things that can be
> done with it. But it seems very promising anyway :-)



As an example:

In [21]: a
Out[21]:
array([[0, 1],
       [1, 0],
       [1, 1],
       [0, 1],
       [1, 0]])

In [22]: a[lexsort((a[:,1],a[:,0]))]
Out[22]:
array([[0, 1],
       [0, 1],
       [1, 0],
       [1, 0],
       [1, 1]])


Hmm, I notice that lexsort requires a tuple and won't accept a list. I
wonder if there is a good reason for that. Travis?

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060502/8676d5ca/attachment.html>


More information about the NumPy-Discussion mailing list