numpy.linalg.cond#
- linalg.cond(x, p=None)[source]#
计算矩阵的条件数。
此函数能够根据 p 的值(参见下面的参数)使用七种不同的范数之一返回条件数。
- 参数:
- x(…, M, N) 类似数组
需要计算条件数的矩阵。
- p{None, 1, -1, 2, -2, inf, -inf, ‘fro’},可选
条件数计算中使用的范数阶数
p
矩阵范数
None
2-范数,直接使用
SVD
计算‘fro’
Frobenius 范数
inf
max(sum(abs(x), axis=1))
-inf
min(sum(abs(x), axis=1))
1
max(sum(abs(x), axis=0))
-1
min(sum(abs(x), axis=0))
2
2-范数(最大奇异值)
-2
最小奇异值
inf 表示
numpy.inf
对象,Frobenius 范数是平方和的平方根范数。
- 返回:
- c{float, inf}
矩阵的条件数。可能为无穷大。
另请参阅
注释
矩阵 x 的条件数定义为 x 的范数乘以 x 的逆矩阵的范数 [1];该范数可以是常用的 L2-范数(平方和的平方根)或许多其他矩阵范数中的一种。
参考文献
[1]G. Strang, Linear Algebra and Its Applications, Orlando, FL, Academic Press, Inc., 1980, pg. 285.
示例
>>> import numpy as np >>> from numpy import linalg as LA >>> a = np.array([[1, 0, -1], [0, 1, 0], [1, 0, 1]]) >>> a array([[ 1, 0, -1], [ 0, 1, 0], [ 1, 0, 1]]) >>> LA.cond(a) 1.4142135623730951 >>> LA.cond(a, 'fro') 3.1622776601683795 >>> LA.cond(a, np.inf) 2.0 >>> LA.cond(a, -np.inf) 1.0 >>> LA.cond(a, 1) 2.0 >>> LA.cond(a, -1) 1.0 >>> LA.cond(a, 2) 1.4142135623730951 >>> LA.cond(a, -2) 0.70710678118654746 # may vary >>> (min(LA.svd(a, compute_uv=False)) * ... min(LA.svd(LA.inv(a), compute_uv=False))) 0.70710678118654746 # may vary