[Numpy-discussion] Second order gradient in numpy
chris.barker at noaa.gov
Fri May 2 15:19:13 EDT 2014
On Thu, May 1, 2014 at 6:00 PM, Yuxiang Wang <yw5aj at virginia.edu> wrote:
> Thank you for your input! I prefer np.gradient because it takes
> mid-point finite difference estimation instead of one-sided estimates,
> but np.diff() is also a good idea. Just wondering why np.gradient does
> not have something similar, being curious :)
well, according to the docs, the second order diff() is just calling diff
twice anyway, so really the same as what you've done with gradient anyway.
I suspect it's just that no one bothered to add that to the gradient API.
BTW, I think that numy can handle piecewise polynomials (i.e. splines), so
depending on the noisiness of your data, a cubic spline fit may give better
gradients -- and if your data are noise second order gradients can get
> On Thu, May 1, 2014 at 6:42 PM, Christian K. <ckkart at hoc.net> wrote:
> > Am 01.05.14 18:45, schrieb Yuxiang Wang:
> >> Hi all,
> >> I am trying to calculate the 2nd-order gradient numerically of an
> >> array in numpy.
> >> import numpy as np
> >> a = np.sin(np.arange(0, 10, .01))
> >> da = np.gradient(a)
> >> dda = np.gradient(da)
> > It looks like you are looking for the derivative rather than the
> > gradient. Have a look at:
> > np.diff(a, n=1, axis=-1)
> > n is the order if the derivative.
> > Christian
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> Yuxiang "Shawn" Wang
> Gerling Research Lab
> University of Virginia
> yw5aj at virginia.edu
> +1 (434) 284-0836
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion