Table of Contents
Shortcuts

# torch.linalg.matrix_exp

torch.linalg.matrix_exp(A) → Tensor

  Computes the matrix exponential of a square matrix.

  Letting K\mathbb{K}K be R\mathbb{R}R or C\mathbb{C}C, this function computes the matrix exponential of A∈K n×n A \in \mathbb{K}^{n \times n}A∈K n×n, which is defined as

  m a t r i x_e x p(A)=∑k=0∞1 k!A k∈K n×n.\mathrm{matrix\_exp}(A) = \sum_{k=0}^\infty \frac{1}{k!}A^k \in \mathbb{K}^{n \times n}. matrix_exp(A)=k=0∑∞​k!1​A k∈K n×n.

  If the matrix A A A has eigenvalues λ i∈C\lambda_i \in \mathbb{C}λ i​∈C, the matrix m a t r i x_e x p(A)\mathrm{matrix\_exp}(A)matrix_exp(A) has eigenvalues e λ i∈C e^{\lambda_i} \in \mathbb{C}e λ i​∈C.

  Supports input of bfloat16, float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if `A` is a batch of matrices then the output has the same batch dimensions.

  Parameters:

    A (Tensor) – tensor of shape (*, n, n) where * is zero or more batch dimensions.

  Example:

      >>> A = torch.empty(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.linalg.matrix_exp(A)
      tensor([[[2.7183, 0.0000],
               [0.0000, 2.7183]],

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

      >>> import math
      >>> A = torch.tensor([[0, math.pi/3], [-math.pi/3, 0]]) # A is skew-symmetric
      >>> torch.linalg.matrix_exp(A) # matrix_exp(A) = [[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

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.