differentiating scipy.interpolate.interp1d

Jür*_*aak 1 interpolation scipy

Given a two vectors x and y I can use scipy.interpolate.interp1d to compute the (quadratic) spline. However I'm not directly interested in the spline itself, but rather in the derivative of the spline. I would prefer having an explicit solution rather than a numerical derivative.

但是我找不到多项式参数存储在哪里interp1d。我尝试过interp1d.__dict__,其中包含interp1d._spline但我没有找到该参数的定义是什么。

小智 5

检查InterpolatedUnivariateSpline,它有derivative 方法: 请注意,为了方便起见,导数返回另一个样条对象,并且您还可以指定导数的阶数(默认为 1)。

from scipy.interpolate import InterpolatedUnivariateSpline as IUS
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10)
y = x**2 + np.random.normal(size=10)

u = IUS(x,y)
u_der = u.derivative()

plt.plot(x, y, 'go')
plt.plot(x, u(x), 'b--')
plt.plot(x, u_der(x), 'k')
Run Code Online (Sandbox Code Playgroud)