[Matrix-SIG] Sorting arrays lexicographically by row
jhauser@ifm.uni-kiel.de
jhauser@ifm.uni-kiel.de
Fri, 23 Apr 1999 11:11:21 +0200 (CEST)
There is argsort, with which one can try to build a custom
sort-function.
But the most easy and probably also efficient method is to use pythons
list sort.
The conversion from an array to a list of lists cost nearly no
time. The sorting on lists is definetly very good optimized.
So use:
>>> a
array([[3, 1],
[3, 0],
[2, 1],
[1, 0],
[2, 2]])
>>> b=a.tolist()
>>> b.sort()
>>> array(b)
array([[1, 0],
[2, 1],
[2, 2],
[3, 0],
[3, 1]])
The steps in between are needed, because the methods do not return
arrays.
HTH,
__Janko
Edward C. Jones writes:
> Here is a small piece of Python code:
>
> arr = [[3,1], [3,0], [2,1], [1,0], [2,2]]
> arr.sort()
> print arr
>
> The output is:
>
> [[1, 0], [2, 1], [2, 2], [3, 0], [3, 1]]
>
> Can I do this (lexicographic) type of sorting using NumPy on a
> NumPy array?
>
> Thanks,
> Ed Jones
>
>
>
> _______________________________________________
> Matrix-SIG maillist - Matrix-SIG@python.org
> http://www.python.org/mailman/listinfo/matrix-sig
>