467,871 Members | 1,693 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,871 developers. It's quick & easy.

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

Dear community,

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

http://www.python.org/doc/2.4.2/lib/...q-mutable.html
http://wiki.python.org/moin/HowTo/Sorting
http://www.python.org/doc/2.4.4/whatsnew/node12.html

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:

http://www.mathworks.com/access/help.../ref/sort.html

'[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);
end'
--

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
Yours,

Orlando

--
Psssst! Schon vom neuen GMX MultiMessenger gehŲrt?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
May 29 '07 #1
  • viewed: 896
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Steven T. Hatton | last post: by
27 posts views Thread by Abdullah Kauchali | last post: by
4 posts views Thread by Deborah V. Gardner | last post: by
17 posts views Thread by Jon | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.