bundles / scipy 1.17.1 / scipy / sparse / linalg / _matfuncs / matrix_power
function
scipy.sparse.linalg._matfuncs:matrix_power
Signature
def matrix_power ( A , power ) Summary
Raise a square matrix to the integer power, power.
Extended Summary
For non-negative integers, A**power is computed using repeated matrix multiplications. Negative integers are not supported.
Parameters
A: (M, M) square sparse array or matrixsparse array that will be raised to power
powerpower: intExponent used to raise sparse array
A
Returns
A**power: (M, M) sparse array or matrixThe output matrix will be the same shape as A, and will preserve the class of A, but the format of the output may be changed.
Notes
This uses a recursive implementation of the matrix power. For computing the matrix power using a reasonably large power, this may be less efficient than computing the product directly, using A @ A @ ... @ A. This is contingent upon the number of nonzero entries in the matrix.
Examples
from scipy import sparse A = sparse.csc_array([[0,1,0],[1,0,1],[0,1,0]]) A.todense() (A @ A).todense() A2 = sparse.linalg.matrix_power(A, 2) A2.todense() A4 = sparse.linalg.matrix_power(A, 4) A4.todense()✓
Aliases
-
scipy.sparse.linalg.matrix_power