numpy.linalg.cond#

linalg.cond(x, p=None)[源代码]#

计算矩阵的条件数.

此函数能够根据 p 的值(见下文参数)返回使用七种不同范数之一的条件数.

参数:
x(…, M, N) array_like

寻求条件数的矩阵.

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