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

PyTorch torch.slogdet function

PyTorch torch.slogdet function


PyTorch torch reference manual PyTorch torch reference manual

torch.slogdet is a function in PyTorch used to compute the sign and logarithm of the determinant of a matrix. It is more numerically stable for cases where the determinant is very large or very small.

Function definition

torch.slogdet(input, out=None)

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 sign and logarithm

sign

,

logdet

=

torch.

slogdet

(

A

)

print

(

"Matrix A:"

)

print

(

A

)

print

(

"nDeterminant sign:"

,

sign

)

print

(

"Log determinant:"

,

logdet

)

print

(

"Determinant:"

,

sign * torch.

exp

(

logdet

)

)

The output is:

矩阵 A:

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

        [0., 4., 5.],

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

行列式符号: tensor(1.)

行列式对数: tensor(3.5835)

行列式: tensor(24.)


PyTorch torch reference manual PyTorch torch reference manual