【问题标题】:scipy PchipInterpolator implementation problemsscipy PchipInterpolator 实现问题
【发布时间】:2021-06-03 10:49:30
【问题描述】:

我正在尝试基于链接实现 PchipInterpolator:

http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.PchipInterpolator.html

我使用的代码是:

x = np.arange(0, 10)
y = np.exp(-x/3.0)
set_interp  =   scipy.interpolate.PchipInterpolator( x, y, extrapolate=True )

我得到的错误是:

TypeError: __init__() got an unexpected keyword argument 'extrapolate'

所以,显然我以错误的方式实施它。我尝试了许多其他方法来实现外推,但都失败了。

【问题讨论】:

  • 你使用的是什么版本的 numpy?它是一个纯 Python 函数,因此您可以使用 ipython 或 inspect 自己查看构造函数及其参数。

标签: python scipy


【解决方案1】:

PchipInterpolator 在 0.14 版本中进行了重构,那时它增加了 extrapolate 关键字。

比较 0.13 版的文档:http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.interpolate.PchipInterpolator.html

0.14 版:http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.PchipInterpolator.html

(免责声明:我参与了该重构)

Scipy 0.13 现在已经很老了,最好考虑升级。

最近的 scipy 版本在interpolate 的一致性方面稍好一些。一方面,所有基于多项式的插值器(PPoly、BPoly、Pchip 和 Akima)都有 extrapolate 关键字。

【讨论】:

    【解决方案2】:

    试试这个:

    from scipy import interpolate
    import numpy as np
    
    
    x = np.arange(0, 10)
    y = np.exp(-x/3.0)
    set_interp  =   interpolate.PchipInterpolator( x, y, extrapolate=True )
    

    我没有错误

    【讨论】:

    • 我仍然遇到同样的错误。我的版本:scipy.version.version 输出 [6]:'0.13.2'。你用的是什么版本
    • @user1243255 我没有收到错误,请参阅我在您的问题下评论的链接,也许它可以解决您的问题
    猜你喜欢
    • 2020-10-12
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 2017-02-03
    • 1970-01-01
    相关资源
    最近更新 更多