<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, May 1, 2014 at 6:00 PM, Yuxiang Wang <span dir="ltr"><<a href="mailto:yw5aj@virginia.edu" target="_blank">yw5aj@virginia.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you for your input! I prefer np.gradient because it takes<br>
mid-point finite difference estimation instead of one-sided estimates,<br>
but np.diff() is also a good idea. Just wondering why np.gradient does<br>
not have something similar, being curious :)<br></blockquote><div><br></div><div>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.</div>

<div><br></div><div>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 *really* noisy</div>

<div><br></div><div>-CHB</div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Shawn<br>
<div class="im HOEnZb"><br>
On Thu, May 1, 2014 at 6:42 PM, Christian K. <<a href="mailto:ckkart@hoc.net">ckkart@hoc.net</a>> wrote:<br>
</div><div class="HOEnZb"><div class="h5">> Am 01.05.14 18:45, schrieb Yuxiang Wang:<br>
>> Hi all,<br>
>><br>
>> I am trying to calculate the 2nd-order gradient numerically of an<br>
>> array in numpy.<br>
>><br>
>>      import numpy as np<br>
>>      a = np.sin(np.arange(0, 10, .01))<br>
>>      da = np.gradient(a)<br>
>>      dda = np.gradient(da)<br>
><br>
> It looks like you are looking for the derivative rather than the<br>
> gradient. Have a look at:<br>
><br>
> np.diff(a, n=1, axis=-1)<br>
><br>
> n is the order if the derivative.<br>
><br>
> Christian<br>
><br>
><br>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
> <a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br>
<br>
<br>
</div></div><div class="im HOEnZb">--<br>
Yuxiang "Shawn" Wang<br>
Gerling Research Lab<br>
University of Virginia<br>
<a href="mailto:yw5aj@virginia.edu">yw5aj@virginia.edu</a><br>
<a href="tel:%2B1%20%28434%29%20284-0836" value="+14342840836">+1 (434) 284-0836</a><br>
<a href="https://sites.google.com/a/virginia.edu/yw5aj/" target="_blank">https://sites.google.com/a/virginia.edu/yw5aj/</a><br>
</div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>

Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a>
</div></div>