Here's how I sorted primarily by field 'a' descending and secondarily by field 'b' ascending:<div>(Note that 'a' is the second column, 'b' is the first)<br><div><div><br><font face="courier new, monospace">>>> data<br>
array([('b', 0.03),</font><div><font face="courier new, monospace">       ('c', 0.03),</font></div><div><span style="font-family:'courier new',monospace">       </span><font face="courier new, monospace">('f', 0.03),</font></div>
<div><span style="font-family:'courier new',monospace">       </span><font face="courier new, monospace">('e', 0.01),</font></div><div><span style="font-family:'courier new',monospace">       </span><font face="courier new, monospace">('d', 0.04),</font></div>
<div><span style="font-family:'courier new',monospace">       </span><font face="courier new, monospace">('a', 0.04)],</font></div><div><span style="font-family:'courier new',monospace">      </span><font face="courier new, monospace">dtype=[('b', '|S32'), ('a', '<f8')])</font></div>
</div><div><font face="courier new, monospace"><div>>>> data.sort(order='b') # sort by b</div><div>>>> data = data[::-1] # reverse</div><div>>>> data[numpy.argsort(data['a'])][::-1] # sort by a and reverse</div>
<div>array([('a', 0.04),</div><div>       ('d', 0.04),</div><div>       ('b', 0.03),</div><div>       ('c', 0.03),</div><div>       ('f', 0.03),</div><div>       ('e', 0.01)], </div>
<div>      dtype=[('b', '|S32'), ('a', '<f8')])</div><div><br class="Apple-interchange-newline"><span style="font-family:arial">My question is whether there's an easier way to do this. Originally I thought it would be possible to just do:</span></div>
<div><span style="font-family:arial"><br></span></div><div><div>>>> data.sort(order=('-a', 'b'))</div><div style="font-family:arial"><br></div><div style="font-family:arial">...indicating that the order of 'a' is descending, but this isn't part of NumPy's sort behavior.</div>
<div style="font-family:arial"><br></div><div style="font-family:arial">Your help is appreciated!</div><div style="font-family:arial"><br></div><div style="font-family:arial">Thank you,</div><div style="font-family:arial">
Patrick</div></div></font></div></div></div>