Matrix singularity checks
Testing whether a square system is singular or nonsingular.
SciPy · Function
Computes the determinant of a square matrix or each square matrix in a stacked array. Singular matrices yield zero, and stacked inputs return one scalar per matrix slice.
SciPy computes a matrix determinant by factoring the input with LU decomposition and multiplying the diagonal entries of the resulting upper-triangular factor. It accepts a single square matrix or stacked square matrices, and promotes single-precision inputs to double precision for the result.
scipy.linalg.det(a, overwrite_a=False, check_finite=True)| Name | Type | Description |
|---|---|---|
a | array_like, shape (..., M, M) | Input array for determinant calculation; its final two dimensions must form square matrices. |
overwrite_a | bool, optional | Whether the input data may be overwritten, potentially improving performance. |
check_finite | bool, optional | Whether to verify that the input contains only finite numbers. |
det: float or complex. For stacked inputs, one scalar is returned for each square slice in the last two dimensions.
import numpy as np
from scipy.linalg import det
matrices = np.array([
[[1.0, 2.0], [3.0, 4.0]],
[[2.0, 0.0], [0.0, 5.0]],
])
print(det(matrices)) # [-2. 10.]Computes one determinant for each 2-by-2 matrix in the stacked input.
Testing whether a square system is singular or nonsingular.
Computing a geometric scaling factor or orientation sign from a linear transformation.
Evaluating determinants across a batch of matrices in numerical workflows.
The function accepts an array whose final two dimensions are square matrix dimensions. For stacked input, it returns one scalar determinant for every matrix slice in those final two dimensions.
Follow-up: What happens to a float32 result? It is promoted to float64; complex64 is promoted to complex128 to reduce overflow risk.
It performs an LU factorization using LAPACK getrf, then multiplies the diagonal entries of the U factor. This avoids explicitly expanding the determinant formula.
Follow-up: How are singular matrices represented? Their determinant is zero, as expected from the factorization result.
overwrite_a permits the implementation to overwrite the input and may improve performance. check_finite controls validation that the matrix contains only finite values and defaults to True.
Follow-up: When might check_finite=False be reasonable? In controlled, validated numerical pipelines where avoiding the check matters and invalid values cannot occur.
scipy.linalg.slogdetscipy.linalg.invscipy.linalg.lunumpy.linalg.det