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

PyTorch torch.linalg.eigh function

PyTorch torch.linalg.eigh function


PyTorch torch reference manual PyTorch torch reference manual

torch.linalg.eigh is a function in PyTorch's linear algebra module used to compute the eigendecomposition of a Hermitian matrix (symmetric or complex conjugate matrix). Compared with ordinary eigendecomposition, it is more efficient and numerically more stable.

Function definition

torch.linalg.eigh(A, UPLO='L', out=None)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create a symmetric matrix

A

=

torch.

tensor

(

[

[

2.0

,

1.0

]

,

                 

[

1.0

,

2.0

]

]

)

Hermitian eigendecomposition

eigenvalues

,

eigenvectors

=

torch.

linalg

.

eigh

(

A

)

print

(

"Matrix A:"

)

print

(

A

)

print

(

"nEigenvalues:"

)

print

(

eigenvalues

)

print

(

"nEigenvectors:"

)

print

(

eigenvectors

)

The output is:

矩阵 A:

tensor([[2., 1.],

        [1., 2.]])

Eigenvalues:

tensor([1., 3.])

Eigenvector:

tensor([[-0.7071,  0.7071],

        [ 0.7071,  0.7071]])


PyTorch torch reference manual PyTorch torch reference manual