Shortcuts

# torch.matrix_exp¶

torch.matrix_exp(input)Tensor

Computes the matrix exponential of a square matrix or of each square matrix in a batch. For a matrix input, the matrix exponential is defined as

$\mathrm{e}^\text{input} = \sum_{k=0}^\infty \text{input}^k / k!$

The implementation is based on:

Bader, P.; Blanes, S.; Casas, F. Computing the Matrix Exponential with an Optimized Taylor Polynomial Approximation. Mathematics 2019, 7, 1174.

Parameters

input (Tensor) – the input tensor.

Example:

>>> a = torch.randn(2, 2, 2)
>>> a[0, :, :] = torch.eye(2, 2)
>>> a[1, :, :] = 2 * torch.eye(2, 2)
>>> a
tensor([[[1., 0.],
[0., 1.]],

[[2., 0.],
[0., 2.]]])
>>> torch.matrix_exp(a)
tensor([[[2.7183, 0.0000],
[0.0000, 2.7183]],

[[7.3891, 0.0000],
[0.0000, 7.3891]]])

>>> import math
>>> x = torch.tensor([[0, math.pi/3], [-math.pi/3, 0]])
>>> x.matrix_exp() # should be [[cos(pi/3), sin(pi/3)], [-sin(pi/3), cos(pi/3)]]
tensor([[ 0.5000,  0.8660],
[-0.8660,  0.5000]])


## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials