[SciPy-user] sorting [WAS: (no subject)]

Steve Schmerler elcorto@gmx....
Mon Aug 20 09:42:27 CDT 2007


Perez Kawumi wrote:
> Hi all,
> Is there a command in python that sorts the elements of a vector in 
> ascending order?
> Thanks
> 

In plain Python, if you use lists you can use the list method sort(), as 
mentioned in the Python tutotial: 
http://docs.python.org/tut/node7.html#l2h-12

lst = [2,4,1,6,2,3]
lst.sort()

However, for numerical operations, you want to use numpy arrays rather 
than lists (much faster).

There is a lot of documentation at http://www.scipy.org/Documentation. A 
good stating point is e.g. http://www.scipy.org/Numpy_Example_List. With 
the text search function of your web browser, you can search for "sort" 
and will find examples on the usage of e.g. numpy.sort(). If you use the 
IPython interactive shell (http://ipython.scipy.org/moin/), you can do
numpy.*sort*? to find all functions wich have the pattern "sort" in 
their name, or simply browse the online help of numpy/scipy with 
help(numpy) or help(scipy) in any Python interactive session.

PS: Please use a Mail Subject :)

-- 
cheers,
steve

Random number generation is the art of producing pure gibberish as 
quickly as possible.


More information about the SciPy-user mailing list