<div>Dear community,</div>
<div> </div>
<div>I want to use the sort function to sort a (nested) list. General information can be found below.</div>
<div> </div>
<div><a href="http://www.python.org/doc/2.4.2/lib/typesseq-mutable.html">http://www.python.org/doc/2.4.2/lib/typesseq-mutable.html</a></div>
<div><a href="http://wiki.python.org/moin/HowTo/Sorting">http://wiki.python.org/moin/HowTo/Sorting</a></div>
<div><a href="http://www.python.org/doc/2.4.4/whatsnew/node12.html">http://www.python.org/doc/2.4.4/whatsnew/node12.html</a></div>
<div> </div>
<div>I want to solve the following problem. Given a list I do not only want to retrieve the sorted list but also the position of the original elements (IX below). The example is taken from Matlab syntax:</div>
<div> </div>
<div><a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/sort.html">http://www.mathworks.com/access/helpdesk/help/techdoc/ref/sort.html</a></div>
<div> </div>
<div>'<tt>[B,IX] = sort(A,...)</tt> also returns an array of indices <tt>IX</tt>, where <tt>size(IX) == size(A)</tt>. If <tt>A</tt> is a vector, <tt>B = A(IX)</tt>. If <tt>A</tt> is an <tt>m</tt>-by-<tt>n</tt> matrix, then each column of
<tt>IX</tt> is a permutation vector of the corresponding column of <tt>A</tt>, such that<pre class="programlisting">for j = 1:n
B(:,j) = A(IX(:,j),j);
end'</pre></div>
<div>--</div>
<div> </div>
<div>A = [ 3 7 5<br> 0 4 2 ];</div>
<div> </div>
<div># in Python: A = [[3,7,5],[0,4,2]]</div>
<div> </div>
<div>[B,IX] = sort(A,2)<br> </div>
<div># sort by rows</div>
<div><br>B =<br> 3 5 7<br> 0 2 4<br><br>IX =<br> 1 3 2<br> 1 3 2</div>
<div> </div>
<div># first line: 3 was formerly in the first position, 5 formerly in position 3, 7 formerly in position 2</div>
<div># second line: similiarly</div>
<div> </div>
<div> </div>
<div>Yours,</div>
<div> </div>
<div>Orlando</div>
<div>--</div>
<div> </div>