[Numpy-discussion] padding options for diff

Peter Creasey p.e.creasey.00 at googlemail.com
Tue Oct 25 13:26:39 EDT 2016

> Date: Mon, 24 Oct 2016 08:44:46 -0400
> From: Matthew Harrigan <harrigan.matthew at gmail.com>
> I posted a pull request <https://github.com/numpy/numpy/pull/8206> which
> adds optional padding kwargs "to_begin" and "to_end" to diff.  Those
> options are based on what's available in ediff1d.  It closes this issue
> <https://github.com/numpy/numpy/issues/8132>

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.


More information about the NumPy-Discussion mailing list