George Sakkis wrote:
> Albert Strasheim wrote:
>
>   
>> 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).
>>     
>
> I'm afraid this won't help in my case; I want to sort twice, once by f1
> and once by f2. I guess I could make a second file with the fields
> swapped but this seems more messy and inefficient than Francesc's
> suggestion.
>   

As a final contribution before I become more quiet for a few weeks (and 
aside from hopefully releasing 1.0.1 soon), I've added a feature to 
allow specifying the sorting order for record arrays.

It's added to the sort method as the order= keyword.  You can pass in a 
string (specifying which field comes first --- all other fields will 
stay in the same order) or you can pass in a list or tuple which 
indicates the field order (any fields un-specified will stay in their 
same relative order).

It works be creating a new data-type object with the .names attribute 
replaced with a newly ordered one and then calling sort on a view of the 
array with that data-type.  The VOID_compare uses the names tuple to 
determine the ordering.

This was the un-named option in my previous list.  It's a better 
solution than all of the others, I think.  The newly created data-type 
is discarded after the sorting is complete.

-Travis


-------------------------------------------------------------------------
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
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to