[Numpy-discussion] partial_sum/adj_difference?

Pierre GM pgmdevlist at gmail.com
Tue Feb 19 15:08:03 EST 2008


> On Feb 19, 2008 11:38 AM, Neal Becker <ndbecker2 at gmail.com> wrote:

> > 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.

There's also numpy.diff, and the little known numpy.ediff1d
>>>x=numpy.arange(10)
>>>numpy.ediff1d(x,to_begin=0)
array([0, 1, 1, 1, 1, 1, 1, 1, 1, 1])



More information about the NumPy-Discussion mailing list