numpy.linalg.cond#
- linalg.cond(x, p=None)[原始碼]#
計算矩陣的條件數。
此函數能夠使用七種不同範數之一傳回條件數,具體取決於 p 的值(請參閱下面的參數)。
- 參數:
- x(…, M, N) 類陣列
尋找條件數的矩陣。
- p{None, 1, -1, 2, -2, inf, -inf, ‘fro’}, optional
用於條件數計算的範數階數
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, 線性代數及其應用, 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