Shortcuts

# torch.linalg.det¶

torch.linalg.det(A, *, out=None) → Tensor

Computes the determinant of a square matrix.

Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if A is a batch of matrices then the output has the same batch dimensions.

Note

This function is computed using torch.lu(). When inputs are on a CUDA device, this function synchronizes that device with the CPU.

torch.linalg.slogdet() computes the sign (resp. angle) and natural logarithm of the absolute value (resp. modulus) of the determinant of real-valued (resp. complex) square matrices.

Parameters

A (Tensor) – tensor of shape (*, n, n) where * is zero or more batch dimensions.

Keyword Arguments

out (Tensor, optional) – output tensor. Ignored if None. Default: None.

Examples:

>>> a = torch.randn(3, 3)
>>> a
tensor([[ 0.9478,  0.9158, -1.1295],
[ 0.9701,  0.7346, -1.8044],
[-0.2337,  0.0557,  0.6929]])
>>> torch.linalg.det(a)
tensor(0.0934)

>>> out = torch.empty(0)
>>> torch.linalg.det(a, out=out)
tensor(0.0934)
>>> out
tensor(0.0934)

>>> a = torch.randn(3, 2, 2)
>>> a
tensor([[[ 0.9254, -0.6213],
[-0.5787,  1.6843]],

[[ 0.3242, -0.9665],
[ 0.4539, -0.0887]],

[[ 1.1336, -0.4025],
[-0.7089,  0.9032]]])
>>> torch.linalg.det(a)
tensor([1.1990, 0.4099, 0.7386]) ## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials