简体   繁体   English

在scipy.interpolate.interp1d中,kind参数的不同值是什么意思?

[英]What do the different values of the kind argument mean in scipy.interpolate.interp1d?

The SciPy documentation explains that interp1d 's kind argument can take the values 'linear' , 'nearest' , 'zero' , 'slinear' , 'quadratic' , 'cubic' . SciPy文档解释了interp1dkind参数可以取值'linear''nearest''zero''slinear''quadratic''cubic' The last three are spline orders and 'linear' is self-explanatory. 最后三个是样条线顺序, 'linear'是不言自明的。 What do 'nearest' and 'zero' do? 'nearest''zero'是什么?

  • nearest "snaps" to the nearest data point. nearest最近的数据点“ nearest ”。
  • zero is a zero order spline. zero是零阶样条。 It's value at any point is the last raw value seen. 它在任何时候的价值都是最后看到的原始价值。
  • linear performs linear interpolation and slinear uses a first order spline. linear执行线性插值,而slinear使用一阶样条。 They use different code and can produce similar but subtly different results . 他们使用不同的代码, 可以产生类似但略有不同的结果
  • quadratic uses second order spline interpolation. quadratic使用二阶样条插值。
  • cubic uses third order spline interpolation. cubic使用三阶样条插值。

Note that the k parameter can also accept an integer specifying the order of spline interpolation. 请注意, 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' returns data point from X nearest to the argument, or interpolates function y=f(x) at the point x using the data point nearest to x 'nearest'返回距离参数最近的X的数据点,或interpolates function y=f(x) at the point x using the data point nearest to x

'zero' I would guess is equivalent to truncation of argument and thus using data point closest toward zero '零'我猜是相当于截断参数,因此使用最接近零的数据点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM