Re: Sorting array



Tartifola wrote:

Hi,
I'm working with numerical array and I'm a little lost on a particular
sorting of one of them. In particular I have an array like

a = array([[8,4,1],[2,0,9]])

and I need to sort it using only the first column as reference but
keeping the lines together so to obtain

array([[2, 0, 9],
[8, 4, 1]])

In [1]: from numpy import *

In [2]: a = array([[8,4,1],[2,0,9]])

In [3]: i = argsort(a[:,0])

In [4]: a[i]
Out[4]:
array([[2, 0, 9],
[8, 4, 1]])


numpy questions are best asked on the numpy-discussion mailing list since
everyone there automatically knows that you are talking about numpy arrays and
not just misnaming lists. ;-)

http://www.scipy.org/Mailing_Lists

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

.



Relevant Pages

  • Re: clean way prepend an element to a numpy array
    ... like I must make a list, insert in place, then make an array again. ... You will want to ask numpy questions on the numpy mailing list. ... "I have come to believe that the whole world is an enigma, a harmless enigma ... an underlying truth." ...
    (comp.lang.python)
  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)
  • Re: Ranking Without Sorting
    ... >> sorting the elements of the array. ... > inverting and applying such a permutation can be done in linear time. ... > You can avoid having to sort the input array by treating the output ...
    (comp.programming)
  • Re: Ranking Without Sorting
    ... > sorting the elements of the array. ... inverting and applying such a permutation can be done in linear time. ... You can avoid having to sort the input array by treating the output ...
    (comp.programming)
  • Re: Ranking Without Sorting
    ... >> contradicted in my first post where I gave an example of how to rank ... > It seems quite clear to me that your 'ranking' array contains the exact ... An unsorted array contains the same information as the same array after sorting. ... > the same operation as the insertion loop in insertion sort... ...
    (comp.programming)