本文簡要介紹 python 語言中 scipy.linalg.ldl
的用法。
用法:
scipy.linalg.ldl(A, lower=True, hermitian=True, overwrite_a=False, check_finite=True)#
計算對稱/厄米矩陣的 LDLt 或 Bunch-Kaufman 分解。
此函數返回一個塊對角矩陣 D,由大小最多為 2x2 的塊以及一個可能置換的單位下三角矩陣組成
L
這樣分解A = L D L^H
或者A = L D L^T
持有。如果降低為 False 則(再次可能置換)上三角矩陣作為外部因子返回。置換數組可用於簡單地通過行洗牌對外部因子進行三角化,即
lu[perm, :]
是一個上/下三角矩陣。這也等同於與置換矩陣相乘P.dot(lu)
,其中P
是 column-permuted 單位矩陣I[:, perm]
。根據布爾值的值,僅引用輸入數組的上三角或下三角部分。因此,輸入時的三角矩陣將給出與提供完整矩陣相同的結果。
- A: array_like
方輸入數組
- lower: 布爾型,可選
這會在分解的下三角外部因子和上三角外部因子之間切換。下三角形 (
lower=True
) 是默認設置。- hermitian: 布爾型,可選
對於complex-valued 數組,這定義了假設是
A = A.conj().T
還是A = A.T
。對於實值數組,此開關無效。- overwrite_a: 布爾型,可選
允許覆蓋 A 中的數據(可能會提高性能)。默認值為假。
- check_finite: 布爾型,可選
是否檢查輸入矩陣是否僅包含有限數。禁用可能會提高性能,但如果輸入確實包含無窮大或 NaN,則可能會導致問題(崩潰、非終止)。
- lu: ndarray
分解的(可能)置換的上/下三角外部因子。
- d: ndarray
分解的塊對角乘數。
- perm: ndarray
row-permutation 索引數組將 lu 帶入三角形。
- ValueError
如果輸入數組不是正方形。
- ComplexWarning
如果給定對角線上具有非零虛部的 complex-valued 數組,並且將 Hermitian 設置為 True。
參數 ::
返回 ::
拋出 ::
注意:
此函數使用
?SYTRF
例程用於對稱矩陣,?HETRF
例程用於 LAPACK 中的 Hermitian 矩陣。有關算法的詳細信息,請參見 [1]。根據 lower 關鍵字值,僅引用輸入數組的下三角部分或上三角部分。此外,這個關鍵字還定義了因式分解的外部因子的結構。
參考:
[1]J.R. Bunch,L. Kaufman,計算慣性和求解對稱線性係統的一些穩定方法,數學。計算。 1977 年第 31 卷。DOI:10.2307/2005787
例子:
給定一個上三角數組
a
表示完整的對稱數組及其條目,獲得l
, ‘d’ 和置換向量燙發:>>> import numpy as np >>> from scipy.linalg import ldl >>> a = np.array([[2, -1, 3], [0, 2, 0], [0, 0, 1]]) >>> lu, d, perm = ldl(a, lower=0) # Use the upper part >>> lu array([[ 0. , 0. , 1. ], [ 0. , 1. , -0.5], [ 1. , 1. , 1.5]]) >>> d array([[-5. , 0. , 0. ], [ 0. , 1.5, 0. ], [ 0. , 0. , 2. ]]) >>> perm array([2, 1, 0]) >>> lu[perm, :] array([[ 1. , 1. , 1.5], [ 0. , 1. , -0.5], [ 0. , 0. , 1. ]]) >>> lu.dot(d).dot(lu.T) array([[ 2., -1., 3.], [-1., 2., 0.], [ 3., 0., 1.]])
相關用法
- Python SciPy linalg.lu_factor用法及代碼示例
- Python SciPy linalg.lsqr用法及代碼示例
- Python SciPy linalg.lu_solve用法及代碼示例
- Python SciPy linalg.lu用法及代碼示例
- Python SciPy linalg.logm用法及代碼示例
- Python SciPy linalg.leslie用法及代碼示例
- Python SciPy linalg.lsmr用法及代碼示例
- Python SciPy linalg.lobpcg用法及代碼示例
- Python SciPy linalg.lgmres用法及代碼示例
- Python SciPy linalg.lstsq用法及代碼示例
- Python SciPy linalg.eigvalsh_tridiagonal用法及代碼示例
- Python SciPy linalg.cdf2rdf用法及代碼示例
- Python SciPy linalg.LaplacianNd用法及代碼示例
- Python SciPy linalg.solve_circulant用法及代碼示例
- Python SciPy linalg.polar用法及代碼示例
- Python SciPy linalg.clarkson_woodruff_transform用法及代碼示例
- Python SciPy linalg.rsf2csf用法及代碼示例
- Python SciPy linalg.hessenberg用法及代碼示例
- Python SciPy linalg.tril用法及代碼示例
- Python SciPy linalg.triu用法及代碼示例
- Python SciPy linalg.svd用法及代碼示例
- Python SciPy linalg.ishermitian用法及代碼示例
- Python SciPy linalg.invhilbert用法及代碼示例
- Python SciPy linalg.factorized用法及代碼示例
- Python SciPy linalg.SuperLU用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.linalg.ldl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。