Pytorch Torch Linalg Eig
# PyTorch torch.linalg.eig Function
* * Pytorch torch Reference Manual](#)
`torch.linalg.eig` is a function in the PyTorch linear algebra module used to compute the eigenvalue decomposition of a square matrix. It returns all eigenvalues and right eigenvectors of the matrix.
### Function Definition
torch.linalg.eig(A, out=None)
**Parameters**:
* `A` (Tensor): Input square matrix.
* `out` (tuple, optional): Output tuple.
**Return Value**:
* `tuple`: Returns a tuple of (eigenvalues, eigenvectors).
* * *
## Usage Example
## Example
import torch
# Create a square matrix
A = torch.tensor([[1.0,2.0],[3.0,4.0]], dtype=torch.complex128)
# EigenvalueDecomposition
eigenvalues, eigenvectors = torch.linalg.eig(A)
print("Matrix A:")
print(A)
print("nEigenvalue:")
print(eigenvalues)
print("nEigenvector:")
print(eigenvectors)
The output result is:
Matrix A: tensor([[1., 2.], [3., 4.]], dtype=torch.complex128)Eigenvalue: tensor([-0.3723+0.j, 5.3723+0.j], dtype=torch.complex128)Eigenvector: tensor([[-0.8246+0.j, -0.4159+0.j], [ 0.5658+0.j, -0.9094+0.j]], dtype=torch.complex128)
* * Pytorch torch Reference Manual](#)
AI is thinking...
[](#)(#)
[PyTorch torch.nn Reference Manual](#)[](#)
[ByteArk Coding Plan supports mainstream large models such as Doubao, GLM, DeepSeek, Kimi, MiniMax, with official direct supply for stability and reliability. Configuration Guide Β₯9.9/ Month - Activate Now](https://maas.xfyun.cn/modelSquare?ch=maas_lm_l2E)
YouTip