scipy.interpolate.splev()出错,不明白来源

时间:2018-01-30 17:43:46

标签: python scipy interpolation

当我使用from scipy.interpolate import splrep x = [2107.19568388, 2107.2161156, 2107.23654721, 2107.25697893, 2107.27741044, 2107.74733769, 2107.76776941, 2107.97208545, 2107.99251717, 2108.01294878, 2108.23769664, 2108.25812816, 2108.4624444, 2108.48287591, 2108.50330763, 2108.68719226, 2108.70762377, 2108.72805548, 2108.7484871, 2108.91194001, 2108.93237163, 2108.95280334, 2108.97323485, 2108.99366647, 2109.11625625, 2109.13668777, 2109.15711938, 2109.17755109, 2109.19798261, 2109.93352091, 2109.95395253, 2109.97438424, 2110.15826877, 2110.17870038, 2110.199132, 2110.21956361, 2110.44431147, 2110.46474308, 2110.64862761, 2110.66905923, 2110.68949094, 2110.70992246, 2110.73035407, 2111.09812333, 2111.11855485] y = [0.608444254293961, 1.1307864656802968, 1.019736639592334, 0.9961412276026707, 0.9592896281866948, 1.2359383661202434, 1.2812703028911483, 0.505895841200648, 0.9512935629735984, 0.9356096606272141, 0.7855456056935104, 0.981954692622873, 1.072663326334132, 1.0593408940891165, 1.1233664656408031, 0.9644455920846516, 0.9314054842890923, 1.0304404875717894, 1.0352072048542664, 1.0450795581773475, 0.872728098339811, 0.9457681125627769, 1.0171913808928397, 0.8019547307735675, 1.0618760993725407, 1.187125996959775, 1.118741742900147, 0.8138502901656298, 0.8938206893668276, 1.1992722199884276, 0.9804337917647384, 1.2044798450916494, 0.37487515771487456, 1.1281341765413573, 1.0916269656818134, 1.0815338524707898, 0.7864996838381028, 1.084513017667964, 0.9275967249553375, 0.9147866697835813, 0.8990815864549077, 0.9901485904924978, 1.0, 1.094349087797393, 1.0823604234628468] b = [2107.07820195, 2109.10604032, 2111.13387869] _ = splrep(x,y,t=b) 时,到目前为止我收到的错误无法解读。 Scipy版本1.0.0和Python版本2.7.6。以下代码重现了它:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nfs/phs3/ar0/S/PROJ/jwallace/venv/lib/python2.7/site-packages/scipy/interpolate/fitpack.py", line 289, in splrep
    res = _impl.splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet)
  File "/nfs/phs3/ar0/S/PROJ/jwallace/venv/lib/python2.7/site-packages/scipy/interpolate/_fitpack_impl.py", line 514, in splrep
    raise _iermess[ier][1](_iermess[ier][0])
ValueError: Error on input data

当我运行时,我收到以下错误:

x

此错误

The answer to this question, with the same problem,是为了确保x按升序排列。这对我来说,这不是问题所在。

This bug report's resolution似乎需要在每个断点之间存在x的值。我b<SetProperty Id="RunStopScript" Before ="RunStopScript" Sequence="execute" Value="&quot;C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe&quot; -NonInteractive -ExecutionPolicy Bypass -InputFormat None -NoProfile -File &quot;[INSTALLDIR]Scripts/StopAppPools.ps1&quot;" /> <CustomAction Id="RunStopScript" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="ignore" Impersonate="no" /> 的组合符合此要求。

我的数据有什么问题?

1 个答案:

答案 0 :(得分:2)

pv's comment in the bug report

  

FITPACK要求结满足条件

xb<t(k+2)<t(k+3)<...<t(n-k-1)<xe
      schoenberg-whitney条件,即那里       必须是数据点xx(j)的子集,以便

t(j) < xx(j) < t(j+k+1), j=1,2,...,n-k-1

因此,t值必须介于xbxe之间,x的起始值和结束值。

由于min(b)max(b)超出范围[xb, xe],因此引发错误:

In [102]: min(b) < np.array(x).min()
Out[102]: True

In [103]: max(b) > np.array(x).max()
Out[103]: True

从scipy版本0.15.0开始,此条件为added to splrep's docstring