[Numpy-discussion] array sort questions
Tim Hochberg
tim.hochberg at ieee.org
Wed Sep 17 13:19:21 CDT 2003
CL WU wrote:
> Hi, group,
> I am new to numpy. I have 2 questions for array sort.
>
> 1. How to sort an array by its one column or one row?
> I know python build-in sort() can do it for list by passing own cmp
> function. but array function sort() will sort each column or row
> seperately,as I know. I don't want to convert array to list to sort
> and then convert back to array.
I think you want argsort plus take. For example, the following sorts on
the second column of a:
a = array([[4,5,6], [1,2,3], [7,8,9]])
arg = argsort(a[:,1])
take(a, arg, 0)
> 2. How to get the rank of a rank-0 array? The first "rank" means the
> order of each element after sorting, instead of the "dimension"
> meaning in numpy. Just like "rank()" function in splus.
If I understand you correctly, you want argsort as mentioned above.
Regards,
-tim
>
> Thank you
>
> Chunlei
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
More information about the Numpy-discussion
mailing list