2011-11-25 71 views
2

Scipyを使用していくつかのデータ点を補間する際に問題があります。私はそれが私が補間しようとしている機能は、大きく4不連続関数をScipyで補間する

ここでxで不連続であるという事実に依存する場合がありますことを推測することは、私が補間するために使用しているコードです:

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

エラーI取得

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 

答えて

5

のどのバージョンあなたは使っていますか?

投稿したスクリプトに構文エラーがあります(コピーと貼り付けが間違っていると思われます)。 このスクリプトはscipy.__version__ == 0.9.0で動作します。 Result picture here

import sys 
from scipy import * 
from scipy.interpolate import * 
from pylab import plot 

x = [] 
y = [] 
for line in sys.stdin: 
    a, b = line.split() 
    x.append(float(a)) 
    y.append(float(b)) 

y_interpolated = interp1d(x,y,bounds_error=False,fill_value=0.,kind='cubic') 
new_x_array = arange(min(x),max(x),0.05) 
plot(new_x_array,y_interpolated(new_x_array),'r-') 
+0

ありがとうございました!私もnumpy.interpで試してみました。 – Brian

関連する問題