Reading records from file and sorting

Albert Strasheim fullung at
Wed Nov 1 16:46:20 CST 2006

Hey George

On Tue, 31 Oct 2006, George Sakkis wrote:

> Is there a more elegant and/or faster way to read some records from a
> file and then sort them by different fields ? What I have now is too
> specific and error-prone in general:
> import numpy as N
> records = N.fromfile(a_file, dtype=N.dtype('i2,i4'))
> records_by_f0 = records.take(records.getfield('i2').argsort())
> records_by_f1 = records.take(records.getfield('i4',2).argsort())
> If there's a better way, I'd like to see it; bonus points for in-place
> sorting.

Check the thread "Strange results when sorting array with fields" from 
about a week back. Travis made some changes to sorting in the presence 
of fields that should solve your problem, assuming your fields appear in 
the order you want to sort (i.e. you want to sort f1, f2, f3 and not 
something like f1, f3, f2).



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