[Numpy-discussion] dunno what array operation I'm looking for...

Hoyt Koepke hoytak@gmail....
Fri Mar 21 21:52:41 CDT 2008


Try

result = A[1:] - A[:-1]

--Hoyt

On Fri, Mar 21, 2008 at 7:43 PM, Chris Withers <chris@simplistix.co.uk> wrote:
> Hi All,
>
>  Say I have an array like:
>
>   >>> measurements = array([100,109,115,117])
>
>  What do I do to it to get:
>
>  array([9, 6, 2])
>
>  Is the following really the best way?
>
>   >>> result = []
>   >>> for i in range(1,len(measurements)):
>  ...   result.append(measurements[i]-measurements[i-1])
>  ...
>   >>> array(result)
>  array([9, 6, 2])
>
>  cheers,
>
>  Chris
>
>  --
>  Simplistix - Content Management, Zope & Python Consulting
>             - http://www.simplistix.co.uk
>  _______________________________________________
>  Numpy-discussion mailing list
>  Numpy-discussion@scipy.org
>  http://projects.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the Numpy-discussion mailing list