Reading records from file and sorting

Travis Oliphant oliphant at ee.byu.edu
Thu Nov 2 10:32:51 CST 2006


George Sakkis wrote:

>Charles R Harris wrote:
>
>  
>
>>On 11/1/06, George Sakkis <george.sakkis at gmail.com> 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.
>>>      
>>>
>>Do you actually want the two different orders, or do you want to sort on the
>>first field, then sort all the items with the same first field on the second
>>field?
>>    
>>
> 
>The former.
>  
>
Sorting on a particular field in-place would be possible if there were 
some-way to indicate to VOID_compare the field-order you wanted to use 
to compare on.

There are a few ways I could think of doing this.

1) Use a  thread-specific global variable (this doesn't recurse very 
easily).
2) Use the meta-object in the field specifier to indicate the order (the 
interface could still be something like
.sort(order='f1')  and a temporary data-type object is created and used).
3) Use a special key in the fields dictionary although this would 
require some fixes to all the code that cycles through the fields 
dictionary to recurse on structures.

4) Overload any of the other variables in the PyArray_Descr * structure.

5) Add a sort-order to the end of the PyArray_Descr * structure and a 
flag to the hasobject flag bits (that would be the last one available) 
that states that the Data-type object has the sort-order defined (so 
binary compatibilty is retained but the new feature can be used going 
forward).

Any other ideas?

-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




More information about the Numpy-discussion mailing list