繁体   English   中英

numpy.linalg.lstsq rcond 参数是否根据描述不起作用?

[英]Is the numpy.linalg.lstsq rcond parameter not working according to the description?

我正在尝试使用 numpy ( Description ) 中的最小二乘解。 根据网站使用'rcond'参数的新默认值:''要使警告静音并使用新默认值,请使用rcond=None,要继续使用旧行为,请使用rcond=-1。''

将 rcond 参数设置为 None:

vector = np.linalg.lstsq(GA, FA, rcond = None)

它返回一个错误:

TypeError: must be real number, not NoneType

当参数被取消或设置为 -1 时,不会发生这种情况。

我做了一些检查,根据这篇文章,其中一个答案有一个更新,说明这种方法最近有一些变化。

然后我想问一下其他人是否有同样的问题,或者我的线路上是否有拼写错误(或者我没有想到的其他问题)。

亲切的问候,感谢您的时间。

你需要 NumPy >= 1.14。 你用的是什么版本?

 x = np.array([0, 1, 2, 3])
 y = np.array([-1, 0.2, 0.9, 2.1])
 A = np.vstack([x, np.ones(len(x))]).T
 print(A)
 m, c = np.linalg.lstsq(A, y, rcond=1.e-10)[0]
 print (m,c)
# rcond must be a float. None as in the documentation 
# gives the "TypeError: a float is required"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM