Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [B,IX] = sort(A,...) - Order for sort()-function

Thread Tools

[B,IX] = sort(A,...) - Order for sort()-function

Posts: n/a
Dear community,

I want to use the sort function to sort a (nested) list. General information can be found below.

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:

'[B,IX] = sort(A,...) also returns an array of indices IX, where size(IX) == size(A). If A is a vector, B = A(IX). If A is an m-by-n matrix, then each column of IX is a permutation vector of the corresponding column of A, such that
for j = 1:n
B(:,j) = A(IX(:,j),j);

A = [ 3 7 5
0 4 2 ];

# in Python: A = [[3,7,5],[0,4,2]]

[B,IX] = sort(A,2)

# sort by rows

B =
3 5 7
0 2 4

IX =
1 3 2
1 3 2

# first line: 3 was formerly in the first position, 5 formerly in position 3, 7 formerly in position 2
# second line: similiarly



Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen:
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
If you get an order # does it mean the order is accepted? =?Utf-8?B?U3RldmUxMDc3?= Windows 64bit 3 05-12-2005 11:46 PM
Two nics, change access order in REGISTRY key?? =?Utf-8?B?TWFjY2E3Nw==?= Wireless Networking 1 01-01-2005 08:32 PM
Traversion order cf. output order in XSL Soren Kuula XML 2 02-01-2004 09:10 AM
In which order are files looked for when loaded/requierd - and what'sthe order of suffixes? Stephan Kämper Ruby 2 01-18-2004 02:07 PM
How to Display DropDownList with preserved order (custom order) cspoh ASP .Net Web Controls 0 07-31-2003 09:19 AM