numpy.linalg.matrix_power(M, n)

Raise a square matrix to the (integer) power n.

For positive integers n, the power is computed by repeated matrix squarings and matrix multiplications. If n=0, the identity matrix of the same type as M is returned. If n<0, the inverse is computed and raised to the exponent.


M : array_like

Must be a square array (that is, of dimension two and with equal sizes).

n : integer

The exponent can be any integer or long integer, positive negative or zero.


M to the power n :

The return value is a an array the same shape and size as M; if the exponent was positive or zero then the type of the elements is the same as those of M. If the exponent was negative the elements are floating-point.


LinAlgException :

If the matrix is not numerically invertible, an exception is raised.

See also

The, operator.


>>> np.linalg.matrix_power(np.array([[0,1],[-1,0]]),10)
array([[-1,  0],
       [ 0, -1]])

Previous topic


Next topic


This Page

Quick search