from scipy.interpolate import spline报错ImportError: cannot import name ‘spline‘
from scipy.interpolate import spline报错ImportError: cannot import name ‘spline‘
一、总结
一句话总结:
导入make_interp_spline而不是spline,spline这个函数现在没了
from scipy.interpolate import make_interp_spline x_smooth = np.linspace(x.min(), x.max(), 300) y_smooth = make_interp_spline(x, y)(x_smooth)
二、from scipy.interpolate import spline报错ImportError: cannot import name ‘spline‘
转自或参考:from scipy.interpolate import spline报错ImportError: cannot import name ‘spline‘
https://blog.csdn.net/lly1122334/article/details/104252039
问题描述
from scipy.interpolate import spline
报错
ImportError: cannot import name 'spline'
解决方案
导入make_interp_spline
并进一步调用
from scipy.interpolate import make_interp_spline
x_smooth = np.linspace(x.min(), x.max(), 300)
y_smooth = make_interp_spline(x, y)(x_smooth)
实例
import numpy as np
from matplotlib import pyplot as plt
from scipy.interpolate import make_interp_spline
x = np.array([6, 7, 8, 9, 10, 11, 12])
y = np.array([1.53E+03, 5.92E+02, 2.04E+02, 7.24E+01, 2.72E+01, 1.10E+01, 4.70E+00])
x_smooth = np.linspace(x.min(), x.max(), 300)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.plot(x_smooth, y_smooth)
plt.show()
参考文献
版权申明:欢迎转载,但请注明出处
一些博文中有一些参考内容因时间久远找不到来源了没有注明,如果侵权请联系我删除。
在校每年国奖、每年专业第一,加拿大留学,先后工作于华东师范大学和香港教育大学。
2025-04-30:宅加太忙,特此在网上找女朋友,坐标上海,非诚勿扰,vx:fan404006308
AI交流资料群:753014672