kind参数的不同值在scipy.interpolate.interp1d中意味着什么? [英] What do the different values of the kind argument mean in scipy.interpolate.interp1d?

查看:730
本文介绍了kind参数的不同值在scipy.interpolate.interp1d中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SciPy文档解释了interp1dkind参数可以采用值‘linear’‘nearest’‘zero’‘slinear’‘quadratic’‘cubic’.最后三个是样条顺序,'linear'是不言自明的. 'nearest''zero'做什么?

The SciPy documentation explains that interp1d's kind argument can take the values ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’. The last three are spline orders and 'linear' is self-explanatory. What do 'nearest' and 'zero' do?

推荐答案

  • nearest快照"到最近的数据点.
  • zero是零阶样条.它的值在任何时候都是最后看到的原始值.
  • linear执行线性插值,而slinear使用第一个 订单样条.他们使用不同的代码,并且可以产生相似但略有不同的结果.
  • quadratic使用二阶样条插值.
  • cubic使用三阶样条插值.
    • nearest "snaps" to the nearest data point.
    • zero is a zero order spline. It's value at any point is the last raw value seen.
    • linear performs linear interpolation and slinear uses a first order spline. They use different code and can produce similar but subtly different results.
    • quadratic uses second order spline interpolation.
    • cubic uses third order spline interpolation.
    • 请注意,k参数还可以接受指定样条插值顺序的整数.

      Note that the k parameter can also accept an integer specifying the order of spline interpolation.

      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()
      

      这篇关于kind参数的不同值在scipy.interpolate.interp1d中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆