Matrix power for sparse matrix in python
问题 I am trying to find out a way to do a matrix power for a sparse matrix M: M^k = M*...*M k times where * is the matrix multiplication (numpy.dot), and not element-wise multiplication . I know how to do it for a normal matrix: import numpy as np import scipy as sp N=100 k=3 M=(sp.sparse.spdiags(np.ones(N), 0, N, N)-sp.sparse.spdiags(np.ones(N), 2, N, N)).toarray() np.matrix_power(M,k) How can I do it for sparse M: M=(sp.sparse.spdiags(np.ones(N), 0, N, N)-sp.sparse.spdiags(np.ones(N), 2, N, N))