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

PyTorch torch.linalg.det function

PyTorch torch.linalg.det function


PyTorch torch reference manual PyTorch torch reference manual

torch.linalg.det is a function in PyTorch's linear algebra module used to compute the determinant of a matrix. It is the torch.det recommended replacement.

Function definition

torch.linalg.det(A)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create a square matrix

A

=

torch.

tensor

(

[

[

1.0

,

2.0

,

3.0

]

,

                 

[

0.0

,

4.0

,

5.0

]

,

                 

[

0.0

,

0.0

,

6.0

]

]

)

Compute the determinant

det_A

=

torch.

linalg

.

det

(

A

)

print

(

"Matrix A:"

)

print

(

A

)

print

(

"Determinant:"

)

print

(

det_A

)

The output is:

矩阵 A:

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

        [0., 4., 5.],

        [0., 0., 6.]])

Determinant:

tensor(24.)


PyTorch torch reference manual PyTorch torch reference manual