[Numpy-discussion] Second order gradient in numpy

Christian K. ckkart at hoc.net
Thu May 1 18:42:59 EDT 2014

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.


More information about the NumPy-Discussion mailing list