用Scipy插值不连续函数

2024-05-14 00:59:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用Scipy插值一些数据点时遇到问题。我想这可能取决于我试图插值的函数在x处是不连续的,大约是4。

下面是我用来插值的代码:

  from scipy import *
  y_interpolated = interp1d(x,y,buonds_error=False,fill_value=0.,kind='cubic')
  new_x_array = arange(min(x),max(x),0.05)
  plot(new_x_array,x_interpolated(new_x_array),'r-')

我得到的错误是

  File "<stdin>", line 2, in <module>
  File "/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 357, in __call__
    out_of_bounds = self._check_bounds(x_new)
  File "/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 415, in _check_bounds
    raise ValueError("A value in x_new is above the interpolation "
ValueError: A value in x_new is above the interpolation range.

以下是我的数据点:

  1.56916432074 -27.9998263169
  1.76773750527 -27.6198430485
  1.98360238449 -27.2397962268
  2.25133982943 -26.8596491107
  2.49319293195 -26.5518194791
  2.77823462692 -26.1896935372
  3.07201297519 -25.9540514619
  3.46090507092 -25.7362456112
  3.65968688527 -25.6453922172
  3.84116464506 -25.53652509
  3.97070419447 -25.3374215879
  4.03087127145 -24.8493356465
  4.08217147954 -24.0540196233
  4.12470899596 -23.0960856364
  4.17612639206 -22.4634289328
  4.19318305992 -22.1380894034
  4.2708234589 -21.902951035
  4.3745696768 -21.9027079759
  4.52158254627 -21.9565591238
  4.65985875536 -21.8839570732
  4.80666329863 -21.6486676004
  4.91026629192 -21.4496126386
  5.05709528961 -21.2685401725
  5.29054655428 -21.2860476871
  5.54129211534 -21.3215908912
  5.73174988353 -21.6645019816
  6.06035782465 -21.772138994
  6.30243916407 -21.7715483093
  6.59656410998 -22.0238656166
  6.86481948673 -22.3665921479
  7.01182409559 -22.4385289076
  7.17609125906 -22.4200564296
  7.37494987052 -22.4376476472
  7.60844044988 -22.5093814451
  7.79869207061 -22.5812017094
  8.00616642549 -22.5445612485
  8.17903446593 -22.4899243886
  8.29141325457 -22.4715846981

Tags: 数据innewvaluelinelibraryscipyarray