使用numpy的polyfit()方法, 报SVD did not converge in Linear Least Squares
2020-07-14 05:46
696 查看
今天正在尝试使用numpy.polyfit()来做多项式拟合的案例
我的代码如下:
# -*- coding:utf-8 -*- import numpy as np import matplotlib.pyplot as mpl p = [-3, 1, 2, 1] x = np.linspace(-10, 10, 1000) y = np.polyval(p, x) mpl.figure('nihe', facecolor='gray') mpl.title("polyfit", fontsize=10) mpl.plot(x, y, color='red', linestyle=':') P = np.polyfit(x, y, 2) y1 = np.polyval(P, x) mpl.plot(x, y1, color='blue', linestyle='-') mpl.show()
结果出现这个错误
raise LinAlgError("SVD did not converge in Linear Least Squares") numpy.linalg.LinAlgError: SVD did not converge in Linear Least Squares
同样的代码在同学的电脑下可以跑,而我的就报错了,难受。
我的numpy的版本是1.18.5
不知道有没有大佬知道这个怎么解决。
已解决
P = np.polyfit(x, y, 2)
y1 = np.polyval(P, x)
写在最前面就ok了
# -*- coding:utf-8 -*- import numpy as np import matplotlib.pyplot as mpl p = [-3, 1, 2, 1] x = np.linspace(-10, 10, 1000) y = np.polyval(p, x) P = np.polyfit(x, y, 2) y1 = np.polyval(P, x) mpl.figure('nihe', facecolor='gray') mpl.title("polyfit", fontsize=10) mpl.plot(x, y, color='red', linestyle=':') mpl.plot(x, y1, color='blue', linestyle='-') mpl.show()
相关文章推荐
- 解决在使用numpy.polyfit 时出现的 raise LinAlgError("SVD did not converge in Linear Least Squares")错误
- linux系统使用sudo命令报xxx is not in the sudoers file.This incident will be reported.的解决方法
- XML methods are not allowed in a GROUP BY clause.XML不允许使用排序方法的处理
- [解决方法]org.dbunit.dataset.NoSuchTableException: Did not find table 'tab1' in schema 'null'
- 安装scipy或者numpy时弹出python2.7 was not found in the registry 的解决办法: python的注册与注销方法
- php使用ZipArchive提示Fatal error: Class ZipArchive not found in的解决方法
- 使用tar解压文件到指定目录时出现Not found in archive的解决方法
- 如何在ACCESS中如何使用IN /NOT IN,以及更高效的方法
- php使用ZipArchive提示Fatal error: Class ZipArchive not found in的解决方法
- 使用hibernateTemplate执行add方法 出现Write operations are not allowed in read-only mode (FlushMode.MANUAL)
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- sharepoint 2010 列表的数据表视图无法使用 the list cannot be displayed in datasheet view 解决方法
- sudo使用问题之——xxx is not in the sudoers file。
- Serv_U 安全设置以后出现530 Not logged in, home directory does not exist的解决方法
- Sorry, the command is not available in this version: syntax enable的解决方法
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- 构造使用IN子句的动态Transact-SQL方法进行编号查询
- 使用Spring提供的Open Session In View而引起Write operations are not allowed in read-only mode (FlushMode.NEVER) 错误解决
- SharePoint2007报出“Code Block are not allowed in this file ”的错误的解决方法
- debian中xxx is not in the sudoers file解决方法