[英]What do the different values of the kind argument mean in scipy.interpolate.interp1d?
SciPy文档解释了interp1d
的kind
参数可以取值'linear'
, 'nearest'
, 'zero'
, 'slinear'
, 'quadratic'
, 'cubic'
。 最后三个是样条线顺序, 'linear'
是不言自明的。 'nearest'
和'zero'
是什么?
nearest
最近的数据点“ nearest
”。 zero
是零阶样条。 它在任何时候的价值都是最后看到的原始价值。 linear
执行线性插值,而slinear
使用一阶样条。 他们使用不同的代码, 可以产生类似但略有不同的结果 。 quadratic
使用二阶样条插值。 cubic
使用三阶样条插值。 请注意, k
参数也可以接受指定样条插值顺序的整数。
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate as interpolate
np.random.seed(6)
kinds = ('nearest', 'zero', 'linear', 'slinear', 'quadratic', 'cubic')
N = 10
x = np.linspace(0, 1, N)
y = np.random.randint(10, size=(N,))
new_x = np.linspace(0, 1, 28)
fig, axs = plt.subplots(nrows=len(kinds)+1, sharex=True)
axs[0].plot(x, y, 'bo-')
axs[0].set_title('raw')
for ax, kind in zip(axs[1:], kinds):
new_y = interpolate.interp1d(x, y, kind=kind)(new_x)
ax.plot(new_x, new_y, 'ro-')
ax.set_title(kind)
plt.show()
'nearest'返回距离参数最近的X的数据点,或interpolates function y=f(x) at the point x using the data point nearest to x
'零'我猜是相当于截断参数,因此使用最接近零的数据点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.