On Feb 19, 2008 11:38 AM, Neal Becker <ndbecker2@gmail.com> wrote:
Does numpy/scipy have a partial_sum and adj_difference function?

partial_sum[i] = \sum_{j=0}^{i} x[j]

Make add.accumulate will do the trick:

In [1]: add.accumulate(arange(10))
Out[1]: array([ 0,  1,  3,  6, 10, 15, 21, 28, 36, 45])

In [3]: arange(10).cumsum()
Out[3]: array([ 0,  1,  3,  6, 10, 15, 21, 28, 36, 45])



adj_diff[i] = x[i] - x[i-1] : i > 1, x[i] otherwise


Well, x[1:] - x[:-1] will give the usual differences. If you need the leading x[0] prefix the x vector with a 0.

In [4]: a = arange(10)

In [5]: b = a[1:] - a[:-1]

In [6]: b
Out[6]: array([1, 1, 1, 1, 1, 1, 1, 1, 1])

Chuck