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

PyTorch torch.lu function

PyTorch torch.lu function


PyTorch torch reference manual PyTorch torch reference manual

torch.lu is a function in PyTorch used to compute the LU decomposition of a matrix. LU decomposition factors matrix A as A = P * L * U, where L is a lower triangular matrix, U is an upper triangular matrix, and P is a permutation matrix.

Function definition

torch.lu(A, pivot=True, get_infos=False, out=None)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create a matrix

A

=

torch.

tensor

(

[

[

1.0

,

2.0

,

3.0

]

,

                 

[

4.0

,

5.0

,

6.0

]

,

                 

[

7.0

,

8.0

,

9.0

]

]

)

LU decomposition

LU

,

pivots

=

torch.

lu

(

A

,

pivot

=

True

)

print

(

"Matrix A:"

)

print

(

A

)

print

(

"nLU matrix:"

)

print

(

LU

)

print

(

"nPivot indices:"

)

print

(

pivots

)

The output is:

矩阵 A:

tensor([[1., 2., 3.],

        [4., 5., 6.],

        [7., 8., 9.]])

LU 矩阵:

tensor([[7., 8., 9.],

        [0.2, 0.4, 0.6],

        [0.6, 0.8, 0.0]])

Primary index:

tensor([3, 3, 3], dtype=torch.int32)

Example - using get_infos

import

torch

A

=

torch.

tensor

(

[

[

1.0

,

2.0

,

3.0

]

,

                 

[

4.0

,

5.0

,

6.0

]

,

                 

[

7.0

,

8.0

,

9.0

]

]

)

LU decomposition with information

LU

,

pivots

,

info

=

torch.

lu

(

A

,

pivot

=

True

,

get_infos

=

True

)

print

(

"Information:"

,

info

)


PyTorch torch reference manual PyTorch torch reference manual