本文簡要介紹 python 語言中 scipy.sparse.linalg.matrix_power
的用法。
用法:
scipy.sparse.linalg.matrix_power(A, power)#
將方陣求整數次方 power。
對於非負整數,
A**power
使用重複的矩陣乘法進行計算。不支持負整數。- A: (M, M) 方稀疏數組或矩陣
稀疏數組將被提升為冪冪
- power: int
用於計算稀疏數組 A 的指數
- A**power: (M, M) 稀疏數組或矩陣
輸出矩陣將與 A 具有相同的形狀,並將保留 A 的類,但輸出的格式可能會更改。
參數 ::
返回 ::
注意:
這使用矩陣冪的遞歸實現。對於使用相當大的冪計算矩陣冪,這可能比使用 A @ A @ … @ A 直接計算乘積的效率要低。這取決於矩陣中非零條目的數量。
例子:
>>> from scipy import sparse >>> A = sparse.csc_array([[0,1,0],[1,0,1],[0,1,0]]) >>> A.todense() array([[0, 1, 0], [1, 0, 1], [0, 1, 0]]) >>> (A @ A).todense() array([[1, 0, 1], [0, 2, 0], [1, 0, 1]]) >>> A2 = sparse.linalg.matrix_power(A, 2) >>> A2.todense() array([[1, 0, 1], [0, 2, 0], [1, 0, 1]]) >>> A4 = sparse.linalg.matrix_power(A, 4) >>> A4.todense() array([[2, 0, 2], [0, 4, 0], [2, 0, 2]])
相關用法
- Python SciPy linalg.matrix_balance用法及代碼示例
- Python SciPy linalg.matmul_toeplitz用法及代碼示例
- Python SciPy linalg.minres用法及代碼示例
- 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.lu_factor用法及代碼示例
- Python SciPy linalg.SuperLU用法及代碼示例
- Python SciPy linalg.lsqr用法及代碼示例
- Python SciPy linalg.cho_factor用法及代碼示例
- Python SciPy linalg.fractional_matrix_power用法及代碼示例
- Python SciPy linalg.eig_banded用法及代碼示例
- Python SciPy linalg.tanhm用法及代碼示例
- Python SciPy linalg.orthogonal_procrustes用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.sparse.linalg.matrix_power。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。