torch.matrix_power¶
-
torch.
matrix_power
(input, n) → Tensor¶ Returns the matrix raised to the power
n
for square matrices. For batch of matrices, each individual matrix is raised to the powern
.If
n
is negative, then the inverse of the matrix (if invertible) is raised to the powern
. For a batch of matrices, the batched inverse (if invertible) is raised to the powern
. Ifn
is 0, then an identity matrix is returned.Example:
>>> a = torch.randn(2, 2, 2) >>> a tensor([[[-1.9975, -1.9610], [ 0.9592, -2.3364]], [[-1.2534, -1.3429], [ 0.4153, -1.4664]]]) >>> torch.matrix_power(a, 3) tensor([[[ 3.9392, -23.9916], [ 11.7357, -0.2070]], [[ 0.2468, -6.7168], [ 2.0774, -0.8187]]])