[SciPy-user] reverse an array

Christopher Brown c-b@asu....
Fri Feb 27 21:25:08 CST 2009


Williamson, Ross wrote:
> Hi everyone
> 
> Is there an easy way to reverse an array without converting it to a list?
> 
> i.e I'm currently doing:
> 
> x = array([0,1,2,3,4])
> x = x.tolist()
> x.reverse()
> x = array(x)
> 
> print x : [4,3,2,1,0]

I found the following code snippet:

 >>> x[::-1]
array([4, 3, 2, 1, 0])

at the following (very helpful) web address:

http://mathesaurus.sourceforge.net/matlab-numpy.html

-- 
Chris



More information about the SciPy-user mailing list