PyTorch torch.det Function
Pytorch torch Reference Manual
torch.detis a function in PyTorch used to compute the determinant of a square matrix.
Function Definition
torch.det(input)
Usage Example
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)
# 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 result is:
tensor(-2.)
torch.logdet Function
torch.logdetis a function in PyTorch used to compute the logarithm of the determinant. When the determinant is positive, it returns log(det); when the determinant is negative or complex, the handling differs.
Function Definition
torch.logdet(input)
Usage Example
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)
# 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 result is:
tensor(nan)
Other Extensions