Strange results when sorting array with fields

Travis Oliphant oliphant.travis at
Mon Oct 23 17:04:14 CDT 2006

Albert Strasheim wrote:
> Hello all
> I'm trying to sort an array with two fields, but I'm getting a result that
> doesn't seem to make sense.
> What I tried (first attempt): I have two 2-D arrays. I would like to sort
> one based on the sort of the other. I managed to do this with argsort.
> However, the fancy indexing required to get the sorted array using what
> argsort returned was very slow. I followed this example:
> b32afd722
> What I tried (second attempt): I created an array with two fields. I
> think/hope/expected that sorting the array would sort it on the first field
> in the dtype and then on the second. This is *much* faster than the fancy
> indexing approach.

O.K.  I lied,

I realized that my comments in the VOID_compare code were silly (about 
being unable to define > or <).  It makes sense to just define them 
based on the first field, then the second field (if the first field is 
equal), and so forth.   Obviously this is not the only way one could 
define sorting (any field could be used as "the first field", and so forth.

But, is is a fairly obvious default to use the first field.  

It turns out, it was not so difficult to implement this and is now in SVN.

So, the VOID_compare now does something a little more intelligent when 
fields are defined which means that record arrays can now be 
lexicographically sorted more easily than using lexsort and take (as 
long as the fields are ordered according to how you want the sort to 


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list