xnx*_*xnx 10 python interpolation scipy
该SciPy的文档解释interp1d的kind争论可以取值‘linear’,‘nearest’,‘zero’,‘slinear’,‘quadratic’,‘cubic’.最后三个是样条顺序,'linear'不言自明.做什么'nearest'和'zero'做什么?
unu*_*tbu 14
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()
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
4799 次 |
| 最近记录: |