PyTorch torch.linalg.det function
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:
A(Tensor): Input square matrix.
Return Value:
torch.Tensor: Returns the determinant of the matrix.
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
)
(
"Matrix A:"
)
(
A
)
(
"Determinant:"
)
(
det_A
)
The output is:
矩阵 A:
tensor([[1., 2., 3.],
[0., 4., 5.],
[0., 0., 6.]])
Determinant:
tensor(24.)