numpy/scipy弃用警告“等级"不正确 [英] Numpy/scipy deprecation warning for "rank"
问题描述
我有一些使用numpy的python代码,并且已经成功运行了一年或一年以上.我上周突然出现以下错误:
I have some python code which uses numpy and have run this successfully for a year or more. I suddenly got the following error last week:
/usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.py:2507: VisibleDeprecationWarning: `rank` is deprecated; use the `ndim` attribute or function instead. To find the rank of a matrix see `numpy.linalg.matrix_rank`.
VisibleDeprecationWarning)
我在网上找不到太多,但是我发现这是由于旧版本scipy中的一个错误引起的(尽管我的代码实际上并未直接使用scipy).我已经用numpy 1.9.2和scipy 0.15.1升级到python 2.7.9,但是我仍然遇到相同的错误.我不确定是什么原因导致的,或者如何解决此问题.
I can't find much on this online, but I found a suggestion that this was due to a bug in old versions of scipy (although my code doesn't actually use scipy directly). I've upgraded to python 2.7.9 with numpy 1.9.2 and scipy 0.15.1, however I'm still getting the same error. I'm not sure what's causing this, or how I fix this.
推荐答案
来自
不推荐使用rank函数,以避免与 The rank function has been deprecated to avoid confusion with 似乎开发人员认为保留单词"rank"表示数组具有线性独立的行数是合适的,而不是用它来表示维数. It seems the developers saw fit to reserve the word "rank" to mean the number of linearly independent rows an array has, and not use it to also mean the number of dimensions. NumPy的主要将来版本中将不提供此功能.因此,不要使用 This function won't be present in major future releases of NumPy. Therefore, instead of using 如果您只想暂时取消该警告,请 If you simply want to suppress the warning for now, the 这篇关于numpy/scipy弃用警告“等级"不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
rank
函数numpy.linalg.matrix_rank
混淆.
rank
functionnumpy.linalg.matrix_rank
.np.rank
查找数组中的维数,而应遵循警告中的建议,并使用数组的ndim
属性或函数np.ndim
.np.rank
to find the number of dimensions in an array, follow the suggestion in the warning and use the ndim
attribute of an array or the function np.ndim
instead.warnings
模块可让您忽略消息.warnings
module allows you to ignore the messages.