PyTorch torch.linalg.eigvals Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.linalg.eigvalsis a function in PyTorch's linear algebra module used to compute eigenvalues of a square matrix. It only returns eigenvalues, not eigenvectors, and is thereforetorch.linalg.eigmore efficient.

Function Definition

torch.linalg.eigvals(A, out=None)

Parameters:

  • A(Tensor): Input square matrix.
  • out(Tensor, optional): Output tensor.

Return Value:

  • torch.Tensor: Returns eigenvalues.

Usage Example

Example

import torch

# Create a square matrix
A = torch.tensor([[1.0, 2.0], [3.0, 4.0]], dtype=torch.complex128)

# Compute eigenvalues
eigenvalues = torch.linalg.eigvals(A)

print("Matrix A:")
print(A)
print("nEigenvalues:")
print(eigenvalues)

The output is:

矩阵 A:
tensor([[1., 2.],
        [3., 4.]], dtype=torch.complex128)
特征值:
tensor([-0.3723+0.j,  5.3723+0.j], dtype=torch.complex128)

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions