I don't really see a justification for assuming that when we're given only
a single sample from a function it must be constant.
On 4 Sep 2013 01:01, "Eric Moore" <notifications@github.com> wrote:

> In numpy/lib/function_base.py:
>
> > -        # 1D equivalent -- out[1:-1] = (f[2:] - f[:-2])/2.0
> > -        out[slice1] = (f[slice2] - f[slice3])/2.0
> > -        slice1[axis] = 0
> > -        slice2[axis] = 1
> > -        slice3[axis] = 0
> > -        # 1D equivalent -- out[0] = (f[1] - f[0])
> > -        out[slice1] = (f[slice2] - f[slice3])
> > -        slice1[axis] = -1
> > -        slice2[axis] = -1
> > -        slice3[axis] = -2
> > -        # 1D equivalent -- out[-1] = (f[-1] - f[-2])
> > -        out[slice1] = (f[slice2] - f[slice3])
> > -
> > +
> > +        if y.shape[axis] < 2:
> > +            raise ValueError("Shape of array too small to calculate a numerical gradient, at least two elements are required.")
>
> This used to raise an IndexError instead of a ValueError. I don't know if
> we care really. I'm not even convinced that just silently returning all
> zeros for in this case would be a bad thing. It would let things like
> np.gradient(np.array([[0,1,2,3,4]])) work.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/numpy/numpy/pull/3654/files#r6142099>
> .
>