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).

Cheers,

Albert

-------------------------------------------------------------------------
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
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to