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

PyTorch torch.orgqr function

PyTorch torch.orgqr function


PyTorch torch reference manual PyTorch torch reference manual

torch.orgqr is a function in PyTorch used to reconstruct the orthogonal matrix Q from a QR decomposition. It uses the Householder reflectors obtained from the QR decomposition to compute the Q matrix.

Function definition

torch.orgqr(input)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create a matrix

A

=

torch.

tensor

(

[

[

12.0

,

51.0

,

4.0

]

,

                 

[

6.0

,

167.0

,

68.0

]

,

                 

[

4.0

,

24.0

,

41.0

]

]

,

dtype

=

torch.

float64

)

QR decomposition

Q

,

R

=

torch.

linalg

.

qr

(

A

)

print

(

"Matrix A:"

)

print

(

A

)

print

(

"nOrthogonal matrix Q:"

)

print

(

Q

)

print

(

"nVerify Q.T @ Q = I:"

)

print

(

Q.

T

@

Q

)

The output is:

矩阵 A:

tensor([[ 12., -51.,   4.],

        [  6., 167., -68.],

        [ -4.,  24., -41.]], dtype=torch.float64)

正交矩阵 Q:

tensor([[-0.8571,  0.3943,  0.3314],

        [-0.4286, -0.9029, -0.0343],

        [ 0.2857, -0.1714,  0.9428]], dtype=torch.float64)

验证 Q.T @ Q = I:

tensor([[ 1.0000e+00, -1.4895e-16,  2.2204e-16],

        [-1.4895e-16,  1.0000e+00,  9.8601e-32],

        [ 2.2204e-16,  9.8601e-32,  1.0000e+00]], dtype=torch.float64)


PyTorch torch reference manual PyTorch torch reference manual