对于以下数据,我正在遵循此问题中给出的建议:
import matplotlib.pyplot as plt
from numpy import array, linspace
from scipy.interpolate import spline
xdata = array([25, 36, 49])
ydata = array([145247, 363726, 789055])
xnew = linspace(xdata.min(),xdata.max(),300)
ysmooth = spline(xdata,ydata,xnew)
plt.plot(xnew,ysmooth)
plt.show()
虽然它适用于该问题中的数据,但由于某种原因,使用此数据,它会中断:
Traceback (most recent call last):
File "test.py", line 526, in <module>
ysmooth = spline(xdata,ydata,xnew)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in spline
return spleval(splmake(xk,yk,order=order,kind=kind,conds=conds),xnew)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 771, in splmake
coefs = func(xk, yk, order, conds, B)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 500, in _find_smoothest
p = np.dual.solve(Q,tmp)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/scipy/linalg/basic.py", line 70, in solve
raise LinAlgError("singular matrix")
numpy.linalg.linalg.LinAlgError: singular matrix
我该如何解决?对于算法来说,这似乎是非常容易拟合的数据。