From: Albert S. <fu...@gm...> - 2006-11-01 22:46:35
|
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 |