zoukankan      html  css  js  c++  java
  • 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()
    

    在这里插入图片描述




    参考文献

    1. matplotlib绘制平滑的曲线
    2. Plot smooth line with PyPlot
     
    我的旨在学过的东西不再忘记(主要使用艾宾浩斯遗忘曲线算法及其它智能学习复习算法)的偏公益性质的完全免费的编程视频学习网站: fanrenyi.com;有各种前端、后端、算法、大数据、人工智能等课程。
    博主25岁,前端后端算法大数据人工智能都有兴趣。
    大家有啥都可以加博主联系方式(qq404006308,微信fan404006308)互相交流。工作、生活、心境,可以互相启迪。
    聊技术,交朋友,修心境,qq404006308,微信fan404006308
    26岁,真心找女朋友,非诚勿扰,微信fan404006308,qq404006308
    人工智能群:939687837

    作者相关推荐

  • 相关阅读:
    0121 集合类 ArrayList 的练习
    0121 有关接口的使用练习
    泛型相关知识
    0120 父类与子类创建、重写及转型练习
    0118练习 单例模式
    java设计模式 略版
    0117 面向对象OOP有关方法、类、构造方法及权限修饰符的练习
    0115 创建类并调用
    [luogu P2586] GCD 解题报告 (莫比乌斯反演|欧拉函数)
    POJ1284 Primitive Roots (原根)
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/13953362.html
Copyright © 2011-2022 走看看