简体   繁体   English

Scipy插值分段多项式-输入数据错误

[英]Scipy Interpolate PiecewisePolynomial - Error on input data

Hello I am using the following code to try to use scipy's interpolation. 您好,我正在使用以下代码尝试使用scipy的插值。

I am getting the following error: 我收到以下错误:

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 3.4.1\helpers\pydev\pydevd.py", line 1733, in <module>
    debugger.run(setup['file'], None, None)
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 3.4.1\helpers\pydev\pydevd.py", line 1226, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:/Users/%user%/PycharmProjects/price_options_multithread/curve_interpolation.py", line 81, in <module>
    tck = interpolate.PiecewisePolynomial(moneyness_,vols_, orders = 2)
  File "C:\Users\%user%\Miniconda\lib\site-packages\scipy\interpolate\polyint.py", line 731, in __init__
    self._set_yi(yi0)
  File "C:\Users\%user%\Miniconda\lib\site-packages\scipy\interpolate\polyint.py", line 131, in _set_yi
    self._y_axis = (axis % yi.ndim)
ZeroDivisionError: integer division or modulo by zero

With the code to call the interpolation reading as: 用该代码调用内插读数为:

tck = interpolate.PiecewisePolynomial(X,Y, orders = 2)

Where Y is: 其中Y是:

[0.2015, 0.3469, 0.2985, 0.2113, 0.19989999999999997, 0.4262, 0.21355000000000002, 0.22260000000000002, 0.21194999999999997, 0.1846, 0.2627, 0.2058, 0.2276, 0.21715, 0.23099999999999998, 0.20235, 0.2165, 0.21165, 0.3836, 0.19594999999999999, 0.20450000000000002, 0.20375, 0.20145000000000002, 0.23525000000000001, 0.2242, 0.22645, 0.27455, 0.22425, 0.2232, 0.1977, 0.19635000000000002, 0.21995, 0.30325, 0.22565]

And X is: X是:

[0.91157701638785, 0.586013796249332, 0.820419314749065, 0.937622073998931, 1.17202759249866, 0.520901152221628, 0.872509429971228, 0.989712189221094, 1.0548248332488, 1.02877977563772, 0.807396785943524, 0.92459954519339, 1.30225288055407, 1.01575724683218, 0.859486901165687, 0.976689660415553, 1.00273471802663, 1.23714023652637, 0.455788508193925, 1.10691494847096, 0.846464372360146, 0.963667131610013, 1.09389241966542, 0.781351728332443, 0.898554487582309, 1.08086989085988, 0.716239084304739, 0.833441843554605, 0.950644602804472, 1.04180230444326, 1.1199374772765, 1.06784736205434, 0.651126440277035, 0.885531958776768]

type(X) and type(Y) give: <type 'list'> type(X)type(Y)给出: <type 'list'>

If I do a polynomial interpolation in excel it looks like the following: 如果我在excel中进行多项式插值,则如下所示: 在此处输入图片说明

Any pointers on what is generating this error would be super helpful. 关于产生此错误的原因的任何指针都将非常有帮助。

Thank you! 谢谢!

The parallel fit using python would be best accomplished using numpy polyfit . 使用python进行并行拟合最好使用numpy polyfit来完成。

Hope this helps someone else in the future. 希望这对以后的人有所帮助。

This is unrelated to the source error - but I will leave to hopefully help someone else. 这与源错误无关-但是我会希望帮助其他人。

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

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