我正在使用scipy.interpolate
函数编写计算Python中1d插值的函数。在文档的帮助下,我编写了两个不同的函数,用于三次和三次样条插值。
# calculate cubic interpolation
def linear_interpolation(x):
linear = interpolate.interp1d(support_x, support_y, 'cubic')
return linear(x)
# calculate cubic spline interpolation
def cubic_spline_interpolation(x):
tck = interpolate.splrep(support_x, support_y)
return interpolate.splev(x, tck)
我有点困惑这里的方法。如果我使用
interpolate.interp1d(support_x, support_y, 'cubic')
,那么它和cubic spline
方法有什么不同?另外,kind = 'quadratic'
和second order spline
之间有什么区别?文档中写道:(参考链接):
“zero”、“slinear”、“quadratic”和“cubic”是指零阶、一阶、二阶或三阶样条插值。
那么为什么我要编写不同的函数来进行三次样条插值,而不是只需将其更改为
kind='cubic'
?