Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

linalg.det

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.

How it works

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.

Syntax

scipy.linalg.det(a, overwrite_a=False, check_finite=True)

Parameters

NameTypeDescription
aarray_like, shape (..., M, M)Input array for determinant calculation; its final two dimensions must form square matrices.
overwrite_abool, optionalWhether the input data may be overwritten, potentially improving performance.
check_finitebool, optionalWhether to verify that the input contains only finite numbers.

Returns

det: float or complex. For stacked inputs, one scalar is returned for each square slice in the last two dimensions.

Key points

  • Computes the determinant of a matrix.
  • A singular matrix produces a determinant of zero.
  • The primary argument is the array whose determinant or determinants should be calculated.
  • For stacked arrays, SciPy calculates one scalar per square slice formed by the last two dimensions.
  • Single-precision real or complex inputs produce float64 or complex128 results.
  • The implementation uses an LU factorization backed by LAPACK's getrf routine.

Common mistakes

  • Turning off finite-value checking can improve speed, but NaNs or infinities may cause crashes or non-termination.
  • With overwrite_a=True, the input may be modified; use it only when that mutation is acceptable.

Example: Determinants for stacked matrices

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.

When to use it

Matrix singularity checks

Testing whether a square system is singular or nonsingular.

Linear transformation analysis

Computing a geometric scaling factor or orientation sign from a linear transformation.

Batched determinant evaluation

Evaluating determinants across a batch of matrices in numerical workflows.

Interview questions

QHow does scipy.linalg.det handle stacked matrices and result shapes?

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.

QHow is the determinant computed internally?

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.

QWhat do overwrite_a and check_finite control?

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.slogdet
  • scipy.linalg.inv
  • scipy.linalg.lu
  • numpy.linalg.det

Source: scipy.linalg.det. Checked 2026-10-15.