Hi,<br><br><div class="gmail_quote">On Thu, Aug 2, 2012 at 3:43 PM, Nicole Stoffels <span dir="ltr"><<a href="mailto:nicole.stoffels@forwind.de" target="_blank">nicole.stoffels@forwind.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear all,<br>
<br>
I have a two-dimensional array:<br>
<br>
a = array([[1,2,3],[0,2,1],[5,7,8]])<br>
<br>
I want to reorder it by the last column in descending order, so that I get:<br>
<br>
b =array([[5, 7, 8],[1, 2, 3],[0, 2, 1]])<br></blockquote><div>Perhaps along the lines:</div><div><font face="courier new, monospace">In []: a</font></div><div><font face="courier new, monospace">Out[]: </font></div><div>
<font face="courier new, monospace">array([[1, 2, 3],</font></div><div><font face="courier new, monospace">       [0, 2, 1],</font></div><div><font face="courier new, monospace">       [5, 7, 8]])</font></div><div><font face="courier new, monospace">In []: ndx= a[:, 2].argsort()</font></div>
<div><font face="courier new, monospace">In []: a[ndx[::-1], :]</font></div><div><font face="courier new, monospace">Out[]: </font></div><div><font face="courier new, monospace">array([[5, 7, 8],</font></div><div><font face="courier new, monospace">       [1, 2, 3],</font></div>
<div><font face="courier new, monospace">       [0, 2, 1]])</font></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
What I did first is the following, which reorders the array in ascending<br>
order (I found that method in the internet):<br>
<br>
b = array(sorted(a, key=lambda new_entry: new_entry[2]))<br>
b = array([[0, 2, 1],[1, 2, 3],[5, 7, 8]])<br>
<br>
But I want it just the other way arround. So I did the following<br>
afterwards which results in an array only containing zeros:<br>
b_indices = b.argsort()<br>
b_matrix = b[b_indices[::-1]]<br>
new_b = b_matrix[len(b_matrix)-1]<br>
<br>
Is there an easy way to reorder it? Or is there at least a complicated<br>
way which produces the right output?<br>
<br>
I hope you can help me! Thanks!<br></blockquote><div>My 2 cents,</div><div>-eat </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Best regards,<br>
<br>
Nicole<br>
<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div><br>