cubic spline interpolation using scipy
![](https://secure.gravatar.com/avatar/9c62c01981eef957711dcd71347296e9.jpg?s=120&d=mm&r=g)
Hello everybody, I have dataset which look like this : position number_of_tag_at_this_position 3 4 8 6 13 25 23 12 I want to apply cubic spline interpolation to this dataset to interpolate tag density; to do so, i run : import numpy as np from scipy import interpolate` x = [3,8,13,23]` y = [4,6,25,12]` tck = interpolate.splrep(x,y) # cubic` And now, i would like to calculate the derivative of the function at each point of the interpolation, How can i do this ? Thanks for your help !
![](https://secure.gravatar.com/avatar/5cb64011e42eaa80576fe9ea326c82d7.jpg?s=120&d=mm&r=g)
Hi, Once you have your spline, you can use interpolate.splev() function to evaluate it on a given set of x values. If you look into the documentation of this function you will see that it can also give you the derivatives - in your case, if you want the first derivative at each point of the interpolation, you should do the following: dy = interpolate.splev(x,tck,der=1) That's it. Cheers, Paweł 2012/11/22 Stéphanie haaaaaaaa <flower_des_iles@hotmail.com>
[4,6,25,12]
participants (2)
-
Paweł Kwaśniewski
-
Stéphanie haaaaaaaa