【发布时间】:2020-06-19 16:48:41
【问题描述】:
我得到的错误行:
from scipy.interpolate import spline
ImportError: cannot import name 'spline'
导致问题的源代码是:
from scipy.interpolate import spline
我尝试了几种安装scipy的方法:
【问题讨论】:
标签: python-3.x scipy python-3.6
我得到的错误行:
from scipy.interpolate import spline
ImportError: cannot import name 'spline'
导致问题的源代码是:
from scipy.interpolate import spline
我尝试了几种安装scipy的方法:
【问题讨论】:
标签: python-3.x scipy python-3.6
spline 不在scipy.interpolate 模块中。您可以改用splrep 或UnivariateSpline。看看documentation中的可用函数。
【讨论】:
spline 已从版本1.3.1 中删除,我回滚到1.2.1 并且它有效!
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()
【讨论】: