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

PyTorch torch.det function

PyTorch torch.det function


PyTorch torch reference manual PyTorch torch reference manual

torch.det is a PyTorch function for computing the determinant of a square matrix.

Function definition

torch.det(input)


Usage examples

Example

import

torch

Create a 2x2 matrix

a

=

torch.

tensor

(

[

[

1.0

,

2.0

]

,

[

3.0

,

4.0

]

]

)

Compute the determinant

y

=

torch.

det

(

a

)

print

(

y

)

The output is:

tensor(-2.)


torch.logdet function

torch.logdet is a PyTorch function for computing the logarithm of the determinant. When the determinant is positive, it returns log(det); when the determinant is negative or complex, it is handled differently.

Function definition

torch.logdet(input)


Usage examples

Example

import

torch

Create a 2x2 matrix

a

=

torch.

tensor

(

[

[

1.0

,

2.0

]

,

[

3.0

,

4.0

]

]

)

Compute the logarithm of the determinant

y

=

torch.

logdet

(

a

)

print

(

y

)

The output is:

tensor(nan)


PyTorch torch reference manual PyTorch torch reference manual