Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.eig function

PyTorch torch.eig function


PyTorch torch reference manual PyTorch torch reference manual

torch.eig is a PyTorch function for computing the eigenvalues and eigenvectors of a square matrix. It returns all eigenvalues and right eigenvectors of the matrix.

Function definition

torch.eig(A, eigenvectors=False, out=None)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create a square matrix

A

=

torch.

tensor

(

[

[

1.0

,

2.0

]

,

[

3.0

,

4.0

]

]

)

Compute eigenvalues

eigenvalues

,

eigenvectors

=

torch.

eig

(

A

,

eigenvectors

=

True

)

print

(

"Matrix A:"

)

print

(

A

)

print

(

"nEigenvalues:"

)

print

(

eigenvalues

)

print

(

"nEigenvectors:"

)

print

(

eigenvectors

)

The output is:

矩阵 A:

tensor([[1., 2.],

        [3., 4.]])

Eigenvalues:

tensor([[-0.3723,  0.0000],

        [ 5.3723,  0.0000]])

Eigenvector:

tensor([[-0.8246, -0.4159],

        [ 0.5658, -0.9094]])


PyTorch torch reference manual PyTorch torch reference manual