<br><br><div class="gmail_quote">On Fri, May 11, 2012 at 9:01 AM, Benjamin Root <span dir="ltr"><<a href="mailto:ben.root@ou.edu" target="_blank">ben.root@ou.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello all,<br><br>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?<br>
</blockquote><div><br>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').<br><br>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.<br>
<br>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.<br>
<br>Chuck<br></div></div>