scipy.linalg.
subspace_angles#
- scipy.linalg.subspace_angles(A, B)[source]#
計算兩個矩陣之間的子空間角度。
- 參數:
- A(M, N) 類陣列
第一個輸入陣列。
- B(M, K) 類陣列
第二個輸入陣列。
- 回傳:
- anglesndarray,形狀 (min(N, K),)
以遞減順序回傳矩陣 A 和 B 之行空間的子空間角度。
註解
此函數根據 [1] 中提供的公式計算子空間角度。為了與 MATLAB 和 Octave 行為等效,請使用
angles[0]
。在 1.0 版本中新增。
參考文獻
[1]Knyazev A, Argentati M (2002) Principal Angles between Subspaces in an A-Based Scalar Product: Algorithms and Perturbation Estimates. SIAM J. Sci. Comput. 23:2008-2040.
範例
一個 Hadamard 矩陣,其具有正交列,因此我們預期子空間角度為 \(\frac{\pi}{2}\)
>>> import numpy as np >>> from scipy.linalg import hadamard, subspace_angles >>> rng = np.random.default_rng() >>> H = hadamard(4) >>> print(H) [[ 1 1 1 1] [ 1 -1 1 -1] [ 1 1 -1 -1] [ 1 -1 -1 1]] >>> np.rad2deg(subspace_angles(H[:, :2], H[:, 2:])) array([ 90., 90.])
且一個矩陣與自身的子空間角度應為零
>>> subspace_angles(H[:, :2], H[:, :2]) <= 2 * np.finfo(float).eps array([ True, True], dtype=bool)
非正交子空間之間的角度介於這些極端值之間
>>> x = rng.standard_normal((4, 3)) >>> np.rad2deg(subspace_angles(x[:, :2], x[:, [2]])) array([ 55.832]) # random