2017-10-21 60 views
1

関数の近似を外挿したい。 scipy.interpolate.interp1dはこれを行うことができます(doc snippetを参照)。 代わりに、私は "ValueError:x_newの値が補間範囲以下になっています。"使用scipy interp1d外挿法fill_value =タプルが機能しない

:パイソン2.7.12、numpyの1.13.3、scipyのダウンロード0.19.1

fill_value : array-like or (array-like, array_like) or "extrapolate", optional - if a ndarray (or float), this value will be used to fill in for requested points outside of the data range. If not provided, then the default is NaN. The array-like must broadcast properly to the dimensions of the non-interpolation axes. - If a two-element tuple, then the first element is used as a fill value for x_new < x[0] and the second element is used for x_new > x[-1] . Anything that is not a 2-element tuple (e.g., list or ndarray, regardless of shape) is taken to be a single array-like argument meant to be used for both bounds as below, above = fill_value, fill_value .

import numpy as np 
from scipy.interpolate import interp1d 
# make a time series 
nobs = 10 
t = np.sort(np.random.random(nobs)) 
x = np.random.random(nobs) 
# compute linear interp (with ability to extrapolate too) 
f1 = interp1d(t, x, kind='linear', fill_value='extrapolate') # this works 
f2 = interp1d(t, x, kind='linear', fill_value=(0.5, 0.6)) # this doesn't 

答えて

0

documentationによると、interp1dデフォルトをするときfill_value='extrapolate'たりするときにbounds_error=Falseを指定除いて外挿にValueErrorを上げるに。

In [1]: f1 = interp1d(t, x, kind='linear', fill_value=(0.5, 0.6), bounds_error=False) 

In [2]: f1(0) 
Out[2]: array(0.5) 
+0

ありがとう、クレイグ。私は、fill_valueにタプル値を供給すると、それが使用されることになると仮定しました(何らかの理由でbounds_error = Falseを明示的に設定しない限り)。これは明らかにinterp1dの動作ではありません。 –

関連する問題