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

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

问题描述

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

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.

这是一个明确的示例:

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

这给出了2的尺寸,我在这里寻找3的答案.

This gives 2 the dimension, where I'm looking for an answer of 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

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

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