[Numpy-discussion] partial_sum/adj_difference?
Pierre GM
pgmdevlist@gmail....
Tue Feb 19 14:08:03 CST 2008
> On Feb 19, 2008 11:38 AM, Neal Becker <ndbecker2@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