scipy.linalg.det#

scipy.linalg.det(a, overwrite_a=False, check_finite=True)[source]#

Compute the determinant of a matrix

The determinant is a scalar that is a function of the associated square matrix coefficients. The determinant value is zero for singular matrices.

Parameters:
a(…, M, M) array_like

Input array to compute determinants for.

overwrite_abool, optional

Allow overwriting data in a (may enhance performance).

check_finitebool, optional

Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.

Returns:
det(…) float or complex

Determinant of a. For stacked arrays, a scalar is returned for each (m, m) slice in the last two dimensions of the input. For example, an input of shape (p, q, m, m) will produce a result of shape (p, q). If all dimensions are 1 a scalar is returned regardless of ndim.

Notes

The determinant is computed by performing an LU factorization of the input with LAPACK routine ‘getrf’, and then calculating the product of diagonal entries of the U factor.

Even the input array is single precision (float32 or complex64), the result will be returned in double precision (float64 or complex128) to prevent overflows.

Examples

>>> import numpy as np
>>> from scipy import linalg
>>> a = np.array([[1,2,3], [4,5,6], [7,8,9]])  # A singular matrix
>>> linalg.det(a)
0.0
>>> b = np.array([[0,2,3], [4,5,6], [7,8,9]])
>>> linalg.det(b)
3.0
>>> # An array with the shape (3, 2, 2, 2)
>>> c = np.array([[[[1., 2.], [3., 4.]],
...                [[5., 6.], [7., 8.]]],
...               [[[9., 10.], [11., 12.]],
...                [[13., 14.], [15., 16.]]],
...               [[[17., 18.], [19., 20.]],
...                [[21., 22.], [23., 24.]]]])
>>> linalg.det(c)  # The resulting shape is (3, 2)
array([[-2., -2.],
       [-2., -2.],
       [-2., -2.]])
>>> linalg.det(c[0, 0])  # Confirm the (0, 0) slice, [[1, 2], [3, 4]]
-2.0