<br><br><div><span class="gmail_quote">On 6/26/07, <b class="gmail_sendername">Charles R Harris</b> <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div><div><span class="e" id="q_1136aab03f2c2308_1"><span class="gmail_quote">On 6/26/07, <b class="gmail_sendername">Charles R Harris</b> <<a href="mailto:charlesr.harris@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
charlesr.harris@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div><span><span class="gmail_quote">On 6/26/07, <b class="gmail_sendername">Tom Denniston</b> <<a href="mailto:tom.denniston@alum.dartmouth.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

tom.denniston@alum.dartmouth.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
In [1]: intArr1 = numpy.array([ 0, 1, 2,-2,-1, 5,-5,-5])<br>In [2]: intArr2 = numpy.array([1,1,1,2,2,2,3,4])<br>In [3]: charArr = numpy.array(['a','a','a','b','b','b','c','d'])
<br><br>Here I sort two int arrays.  As expected intArr2 dominates intArr1 but<br>the items with the same intArr2 values are sorted forwards according<br>to intArr1<br>In [6]: numpy.lexsort((intArr1, intArr2))<br>Out[6]: array([0, 1, 2, 3, 4, 5, 6, 7])
<br><br>This,  however, looks like a bug to me.  Here I sort an int array and<br>a str array.  As expected charArray dominates intArr1 but the items<br>with the same charArray values are sorted *backwards* according to<br>


intArr1<br>In [5]: numpy.lexsort((intArr1, charArr))<br>Out[5]: array([2, 1, 0, 5, 4, 3, 6, 7])<br><br>Is this a bug or am I missing something?</blockquote></span></div></blockquote></span></div></div></blockquote><div><br>
It was a bug. It is fixed in svn.<br><br>Chuck<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div><span class="e" id="q_1136aab03f2c2308_1">
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div>Looks like a bug.<br><br>In [12]: numpy.argsort([charArr], kind='m')
<br>Out[12]: array([[2, 1, 0, 5, 4, 3, 6, 7]])<br><br>In [13]: numpy.argsort([intArr2], kind='m')<br>Out[13]: array([[0, 1, 2, 3, 4, 5, 6, 7]])<br><br>Both of these are stable sorts, and since the elements are in order should return [[0, 1, 2, 3, 4, 5, 6, 7]]. Actually, I think they should return [0, 1, 2, 3, 4, 5, 6, 7], I'm not sure why the returned array is 2D and I suspect that is a bug also. As to why the string array sorts incorrectly, I am not sure. It could be that the sort isn't stable, there could be a stride error, or the comparison is returning wrong values. My bet is on the first being the case.
</div></div></blockquote></span></div><div><br>Nevermind the 2D thingee, that was pilot error in changing lexsort to argsort, charArr should not be in a list:<br><br>In [25]: numpy.argsort(charArr, kind='m', axis=0)
<br>Out[25]: array([2, 1, 0, 5, 4, 3, 6, 7])
<br><br>Works just fine.<br><br>Chuck<br></div></div><br>
</blockquote></div><br>