[Numpy-discussion] padding options for diff
harrigan.matthew at gmail.com
Wed Oct 26 16:18:05 EDT 2016
Would it be preferable to have to_begin='first' as an option under the
existing kwarg to avoid overlapping?
On Wed, Oct 26, 2016 at 3:35 PM, Peter Creasey <
p.e.creasey.00 at googlemail.com> wrote:
> > Date: Wed, 26 Oct 2016 09:05:41 -0400
> > From: Matthew Harrigan <harrigan.matthew at gmail.com>
> > np.cumsum(np.diff(x, to_begin=x.take(, 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))
> > I'm not sure if this means the API should change, and if so how. Higher
> > dimensional arrays seem to just have extra complexity.
> >> 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.
> So my suggestion was intended that you might want an additional
> keyword argument (keep_left=False) to make the inverse np.cumsum
> use-case easier, i.e. you would have something in your np.diff like:
> if keep_left:
> if to_begin is None:
> to_begin = np.take(a, , axis=axis)
> raise ValueError(‘np.diff(a, keep_left=False, to_begin=None)
> can be used with either keep_left or to_begin, but not both.’)
> Generally I try to avoid optional keyword argument overlap, but in
> this case it is probably justified.
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion