区分scipy.interpolate.interp1d

时间:2018-11-28 12:31:42

标签: scipy interpolation

给出两个向量xy,我可以使用scipy.interpolate.interp1d来计算(二次)样条。但是,我对花键本身并不直接感兴趣,而是对花键的派生方式感兴趣。 我希望有一个明确的解决方案,而不是数值导数。

但是我找不到多项式参数存储在interp1d中的位置。 我尝试了interp1d.__dict__,其中包含interp1d._spline,但是我没有找到此参数的定义。

1 个答案:

答案 0 :(得分:2)

选中InterpolatedUnivariateSpline,它具有derivative method:请注意,为方便起见,导数返回了另一个样条线对象,还可以指定导数的顺序(默认为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')