SciPy 尝试导入样条时导入错误

SciPy import error when try to import spline

我得到的错误行:

    from scipy.interpolate import spline
ImportError: cannot import name 'spline'

导致问题的源代码是:

from scipy.interpolate import spline

我试过几种安装方法scipy:

spline 不在 scipy.interpolate 模块中。您可以改用 splrepUnivariateSpline。查看 documentation.

中的可用函数
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import interp1d

x = np.linspace(0, 10, num=11, endpoint=True)
y = np.cos(-x**2/9.0)
f1 = interp1d(x, y, kind='nearest')
f2 = interp1d(x, y, kind='zero')
f3 = interp1d(x, y, kind='quadratic')

xnew = np.linspace(0, 10, num=1001, endpoint=True)
plt.plot(x, y, 'o')
plt.plot(xnew, f1(xnew), '-', xnew, f2(xnew), '--', xnew, f3(xnew), ':')
plt.legend(['data', 'nearest', 'zero', 'quadratic'], loc='best')
plt.show()