PyTorch torch.linalg.det Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.linalg.detIt is a function used to compute the determinant of a matrix in PyTorch's linear algebra module. It istorch.detthe recommended alternative function.

Function Definition

torch.linalg.det(A)

Parameters:

  • A(Tensor): Input square matrix.

Return Value:

  • torch.Tensor: Returns the determinant of the matrix.

Usage Example

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 result is:

矩阵 A:
tensor([[1., 2., 3.],
        [0., 4., 5.],
        [0., 0., 6.]])
行列式:
tensor(24.)

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions