# matrix_power¶

paddle.linalg. matrix_power ( x, n, name=None ) [source]

Computes the n-th power of a square matrix or a batch of square matrices.

Let \(X\) be a square matrix or a batch of square matrices, \(n\) be an exponent, the equation should be:

\[Out = X ^ {n}\]

Specifically,

• If n > 0, it returns the matrix or a batch of matrices raised to the power of n.

• If n = 0, it returns the identity matrix or a batch of identity matrices.

• If n < 0, it returns the inverse of each matrix (if invertible) raised to the power of abs(n).

Parameters
• x (Tensor) – A square matrix or a batch of square matrices to be raised to power n. Its shape should be [*, M, M], where * is zero or more batch dimensions. Its data type should be float32 or float64.

• n (int) – The exponent. It can be any positive, negative integer or zero.

• name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

• Tensor, The n-th power of the matrix (or the batch of matrices) x. Its data type should be the same as that of x.

Examples

>>> x = paddle.to_tensor([[1, 2, 3],
...                       [1, 4, 9],
...                       [1, 8, 27]], dtype='float64')
[[6.  , 34. , 102.],
[14. , 90. , 282.],
[36. , 250., 804.]])