[Numpy-discussion] partial_sum/adj_difference?

Pauli Virtanen pav@iki...
Tue Feb 19 13:48:22 CST 2008


ti, 2008-02-19 kello 13:38 -0500, Neal Becker kirjoitti:
> Does numpy/scipy have a partial_sum and adj_difference function?
> 
> partial_sum[i] = \sum_{j=0}^{i} x[j]
> adj_diff[i] = x[i] - x[i-1] : i > 1, x[i] otherwise

cumsum and diff do something like this:

>>> import numpy
>>> a = [1,2,3,4,5,3,1]
>>> numpy.cumsum(a)
array([ 1,  3,  6, 10, 15, 18, 19])
>>> numpy.diff(a)
array([ 1,  1,  1,  1, -2, -2])

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digitaalisesti allekirjoitettu viestin osa
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080219/9a619e84/attachment.bin 


More information about the Numpy-discussion mailing list