sort

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

sort

wilson-4
i have a 1 dimensional array of floats that i want to sort in
descending order.i did as follows

from numpy import tolist,array,sort
y=array([......]) #may be 1000 items
z=sort(y)
l=z.tolist()
l.reverse()
rl=array(l)

now rl is a 1 dim array sorted in descending order.
but i am looking for a better,compact way to do this.can someone help?

_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: sort

Robert Kern-2
On Thu, Apr 17, 2008 at 5:18 AM, wilson <[hidden email]> wrote:

> i have a 1 dimensional array of floats that i want to sort in
>  descending order.i did as follows
>
>  from numpy import tolist,array,sort
>  y=array([......]) #may be 1000 items
>  z=sort(y)
>  l=z.tolist()
>  l.reverse()
>  rl=array(l)
>
>  now rl is a 1 dim array sorted in descending order.
>  but i am looking for a better,compact way to do this.can someone help?

rl = sort(y)[::-1]

--
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
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: sort

Gael Varoquaux
In reply to this post by wilson-4
On Thu, Apr 17, 2008 at 03:18:45AM -0700, wilson wrote:
> i have a 1 dimensional array of floats that i want to sort in
> descending order.i did as follows

> from numpy import tolist,array,sort
> y=array([......]) #may be 1000 items
> z=sort(y)
> l=z.tolist()
> l.reverse()
> rl=array(l)

> now rl is a 1 dim array sorted in descending order.
> but i am looking for a better,compact way to do this.can someone help?

Not tested, but something like
y = array([......]) #may be 1000 items
y.sort()
y = y[::-1]

Gaƫl
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion