On Fri, May 11, 2012 at 12:00 PM, Charles R Harris <
[email protected]> wrote:

>
>
> On Fri, May 11, 2012 at 9:01 AM, Benjamin Root <[email protected]> wrote:
>
>> Hello all,
>>
>> I need to sort a structured array in a stable manner.  I am also sorting
>> only by one of the keys, so I don't think lexsort() is stable in that
>> respect.  np.sort() allows for choosing 'mergesort', but it appears to not
>> be implemented for structured arrays.  Am I going to have to create a new
>> plain array out of the one column I want to sort by, and run np.artsort()
>> with the mergesort in order to get around this?  Or is there something more
>> straightforward that I am missing?
>>
>
> Lexsort is just a sequence of indirect merge sorts, so using it to sort on
> a single column is the same as calling argsort(..., kind='mergesort').
>
> Mergesort (and heapsort) need to be extended to object arrays and arrays
> with specified comparison functions. I think that would be an interesting
> project for someone, I've been intending to do it myself but haven't got
> around to it.
>
> But as to your current problem, you probably need to have the keys in a
> plain old array. They also need to be in a contiguous array, but the sort
> methods take care of that by making contiguous copies when needed. Adding a
> step parameter to the sorts is another small project for someone. There is
> an interesting trade off there involving cache vs copy time vs memory usage.
>
> Chuck
>
>
Ok, that clears it up for me.  I ended up just doing an
argsort(np.array(d['vtime']), kind=...) and use the indices as a guide.  My
purpose didn't require a resorted array anyway, so this will do for now.

Thanks,
Ben Root
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to