使用 scipy 计算矩阵等级 [英] Calculate Matrix Rank using scipy

查看:37
本文介绍了使用 scipy 计算矩阵等级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是一个明确的例子:

from numpy import matrix, rankA = 矩阵([[1,3,7],[2,8,3],[7,8,1]])打印等级(A)

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

解决方案

Numpy 提供 numpy.linalg.matrix_rank():

<预><代码>>>>导入 numpy>>>numpy.__version__'1.5.1'>>>A = numpy.matrix([[1,3,7],[2,8,3],[7,8,1]])>>>numpy.linalg.matrix_rank(A)3

I'd like to calculate the mathematical rank of a matrix using scipy. The most obvious function numpy.rank calculates the dimension of an array (ie. scalars have dimension 0, vectors 1, matrices 2, etc...). I am aware that the numpy.linalg.lstsq module has this capability, but I was wondering if such a fundamental operation is built into the matrix class somewhere.

Here is an explicit example:

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

This gives 2 the dimension, where I'm looking for an answer of 3.

解决方案

Numpy provides 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

这篇关于使用 scipy 计算矩阵等级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆