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

PyTorch torch.svd_lowrank function

PyTorch torch.svd_lowrank function


PyTorch torch reference manual PyTorch torch reference manual

torch.svd_lowrank is a function in PyTorch used to compute a low-rank approximation of the SVD of a matrix. It uses randomized methods to compute a partial SVD, which is faster than a full SVD.

Function definition

torch.svd_lowrank(A, q=6, niter=2, mexp=2)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create a large matrix

A

=

torch.

randn

(

100

,

50

)

Low-rank SVD (compute the first 10 singular values)

U

,

S

,

V

=

torch.

svd_lowrank

(

A

,

q

=

10

)

print

(

"Shape of matrix A:"

,

A.

shape

)

print

(

"U shape:"

,

U.

shape

)

print

(

"Shape of singular values S:"

,

S.

shape

)

print

(

"V shape:"

,

V.

shape

)

print

(

"nSingular values:"

)

print

(

S

[

:

10

]

)

The output is:

矩阵 A 形状: torch.Size([100, 50])

U 形状: torch.Size([100, 10])

奇异值 S 形状: torch.Size([10])

V 形状: torch.Size([50, 10])

Singular values:

tensor([14.6526, 14.0891, 13.5830, 13.0966, 12.7677, 12.4337, 12.1510,

        11.8361, 11.5309, 11.3064])


PyTorch torch reference manual PyTorch torch reference manual