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

Discussion in 'Python' started by =?iso-8859-1?Q?=22Orlando_D=F6hring=22?=, May 29, 2007.

  1. 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/typesseq-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/helpdesk/help/techdoc/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
    =?iso-8859-1?Q?=22Orlando_D=F6hring=22?=, May 29, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Soren Kuula
    Replies:
    2
    Views:
    474
    Soren Kuula
    Feb 1, 2004
  2. nobody
    Replies:
    0
    Views:
    521
    nobody
    Jun 1, 2004
  3. cspoh
    Replies:
    0
    Views:
    231
    cspoh
    Jul 31, 2003
  4. Navin
    Replies:
    1
    Views:
    659
    Ken Schaefer
    Sep 9, 2003
  5. GIMME
    Replies:
    5
    Views:
    174
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
Loading...

Share This Page