python - 使用 scipy 计算矩阵排名

标签 python matrix numpy scipy

我想计算mathematical rank使用 scipy 的矩阵。最明显的函数 numpy.rank 计算数组的维数(即标量的维数为 0,向量为 1,矩阵为 2,等等...)。我知道 numpy.linalg.lstsq 模块具有此功能,但我想知道这样的基本操作是否内置在某处的矩阵类中。

这是一个明确的例子:

from numpy import matrix, rank
A = matrix([[1,3,7],[2,8,3],[7,8,1]])
print rank(A)

这给了 2 维度,我正在寻找 3 的答案。

最佳答案

Numpy 提供 numpy.linalg.matrix_rank():

>>> import numpy
>>> numpy.__version__
'1.5.1'
>>> A = numpy.matrix([[1,3,7],[2,8,3],[7,8,1]])
>>> numpy.linalg.matrix_rank(A)
3

关于python - 使用 scipy 计算矩阵排名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2473983/

相关文章:

python - 值错误: Input 0 of layer dense_1 is incompatible with the layer

matrix - hlsl矩阵乘法

python - 提取 csv 文件特定列以在 Python 中列出

python - 将 Pandas tseries 对象转换为 DataFrame

python - 使用 odbc_connect 从 SQLAlchemy 连接到 SQL 服务器

c++ - 初始化矩阵

python - 在 python 中,如何让 urllib 将字符串中的多行识别为单独的 URL?

python - 在 numexpr 中限制子表达式

python - 使用参数编写函数

python - 3D矩阵透视变换