Re: [Numpy-discussion] padding options for diff

I like the proposal, though I suspect that making it general has obscured that the most common use-case for padding is to make the inverse of np.cumsum (at least that’s what I frequently need), and now in the multidimensional case you have the somewhat unwieldy:
np.diff(a, axis=axis, to_begin=np.take(a, 0, axis=axis))
rather than
np.diff(a, axis=axis, keep_left=True)
which of course could just be an option upon what you already have. Best, Peter

The inverse of cumsum is actually a little more unweildy since you can't drop a dimension with take. This returns the original array (numerical caveats aside): np.cumsum(np.diff(x, to_begin=x.take([0], axis=axis), axis=axis), axis=axis) That's certainly not going to win any beauty contests. The 1d case is clean though: np.cumsum(np.diff(x, to_begin=x[0])) I'm not sure if this means the API should change, and if so how. Higher dimensional arrays seem to just have extra complexity. On Tue, Oct 25, 2016 at 1:26 PM, Peter Creasey < p.e.creasey.00@googlemail.com> wrote:

The inverse of cumsum is actually a little more unweildy since you can't drop a dimension with take. This returns the original array (numerical caveats aside): np.cumsum(np.diff(x, to_begin=x.take([0], axis=axis), axis=axis), axis=axis) That's certainly not going to win any beauty contests. The 1d case is clean though: np.cumsum(np.diff(x, to_begin=x[0])) I'm not sure if this means the API should change, and if so how. Higher dimensional arrays seem to just have extra complexity. On Tue, Oct 25, 2016 at 1:26 PM, Peter Creasey < p.e.creasey.00@googlemail.com> wrote:
participants (2)
-
Matthew Harrigan
-
Peter Creasey