[Numpy-discussion] Second order gradient in numpy

Yuxiang Wang yw5aj at virginia.edu
Thu May 1 21:00:08 EDT 2014


Hi Christian,

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 :)

Shawn

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
https://sites.google.com/a/virginia.edu/yw5aj/



More information about the NumPy-Discussion mailing list