tf.keras.ops.matrix_power

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 shape as x is returned. If n < 0, the inverse is computed and then raised to the abs(n).

x Input tensor of shape (..., M, M).
n Exponent (integer).

A tensor of shape (..., M, M) representing x**n.

Example:

x = keras.ops.convert_to_tensor([[1., 2.], [3., 4.]])
matrix_power(x, 3)
array([[ 37.,  54.],
       [ 81., 118.]], dtype=float32)