如何确定一个矩阵在python-numpy中是否是奇异的? [英] How to decide a whether a matrix is singular in python-numpy?

查看:1639
本文介绍了如何确定一个矩阵在python-numpy中是否是奇异的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定python-numpy是否可以帮助我们确定矩阵是否为奇数.我试图根据行列式进行决定,但是numpy会在1.e-10左右产生一些值,并且不确定应该为临界值选择什么.

I am not sure whether python-numpy can help us decide whether a matrix is singular or not. I am trying to decide based on the determinant, but numpy is producing some values around 1.e-10 and not sure what should we choose for a critical value.

推荐答案

在默认公差下使用np.linalg.matrix_rank.关于该函数的文档字符串有一些讨论,关于考虑零的奇异值的适当截止点是什么:

Use np.linalg.matrix_rank with the default tolerance. There's some discussion on the docstring of that function on what is an appropriate cutoff to consider a singular value zero:

>>> a = np.random.rand(10, 10)
>>> b = np.random.rand(10, 10)
>>> b[-1] = b[0] + b[1] # one row is a linear combination of two others
>>> np.linalg.matrix_rank(a)
10
>>> np.linalg.matrix_rank(b)
9
>>> def is_invertible(a):
...     return a.shape[0] == a.shape[1] and np.linalg.matrix_rank(a) == a.shape[0]
... 
>>> is_invertible(a)
True
>>> is_invertible(b)
False

这篇关于如何确定一个矩阵在python-numpy中是否是奇异的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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