Python scipy interp1d中的错误
我不理解interp1d报告的结果。我在应该接收数字的地方接收NANPython scipy interp1d中的错误,python,scipy,Python,Scipy,我不理解interp1d报告的结果。我在应该接收数字的地方接收NAN In [131]: bb Out[131]: array([ 0. , 1.80286595, 1.87443683, 2.70410611, 3.02764722, 3.11305985, 3.11534355, 3.18695351, 3.20693444]) In [132]: alphas1 Out[134]: array([ 3.80918778e+00, 2.
In [131]: bb
Out[131]:
array([ 0. , 1.80286595, 1.87443683, 2.70410611, 3.02764722,
3.11305985, 3.11534355, 3.18695351, 3.20693444])
In [132]: alphas1
Out[134]:
array([ 3.80918778e+00, 2.06547222e+00, 1.99234191e+00,
7.55942418e-01, 2.56971574e-01, 1.05144676e-01,
9.30852046e-02, 1.52574183e-02, 1.23664407e-07])
In [135]: bb.shape
Out[135]: (9,)
In [136]: alphas1.shape
Out[140]: (9,)
In [141]: pol = interp1d(alphas1, bb, bounds_error=False)
In [149]: pol(pol.x)
Out[149]: array([ nan, nan, nan, nan, nan, nan, nan, nan, nan]) # I was expecting to receive nan only at the borders.
我认为,如果您检查
interp1d
类的方法,即\u check\u bounds
方法,可以看出问题:
def _check_bounds(self, x_new):
...
below_bounds = x_new < self.x[0]
above_bounds = x_new > self.x[-1]
# !! Could provide more information about which values are out of bounds
if self.bounds_error and below_bounds.any():
raise ValueError("A value in x_new is below the interpolation "
"range.")
if self.bounds_error and above_bounds.any():
raise ValueError("A value in x_new is above the interpolation "
"range.")
现在,
alphas1
将如scipy所预期的那样增加,pol(pol.x)
将按预期返回bb
。哪个版本?给出了scipy 0.14.0中np.array([3.20693444,3.18695351,…
in[25]:np.version.version Out[29]:[30]:scipy.version.version Out[44]:“0.13.3”Updatescipy
中的numpy 1.8.1
的正确答案,它可能会消失。谢谢,它没有工作!
bb = bb[::-1]
alphas1 = alphas[::-1]
pol = interp1d(alphas1, bb, bounds_error=False)