A robot calibration report might retain a determinant to summarize how a square matrix scales volume or to compare covariance estimates in a common coordinate system. The scalar can exceed the range of the numerical type even when every matrix entry is finite. A calculation that turns a tiny determinant into zero loses a distinction that the report may need. Zero after underflow can look the same as zero from a genuinely singular matrix.
NumPy's slogdet stores the sign and the natural logarithm of the magnitude separately. This article uses invented diagonal matrices that were evaluated with NumPy 2.5.2. The extreme values are chosen to expose the numerical behavior. They are not proposed settings, measurement uncertainties, or results from a robot calibration.
Compare three matrices in the same batch
The first matrix is a four-dimensional identity scaled by 1e-100. The determinant of a diagonal matrix is the product of the diagonal entries. Its mathematical determinant here is 1e-400. A float64 cannot represent that positive value. The second matrix uses 1e100 on the diagonal and has a mathematical determinant of 1e400, beyond the largest finite float64. The third has three ones and one zero on the diagonal, so its determinant is exactly zero.
import numpy as np
small = np.eye(4) * 1e-100
large = np.eye(4) * 1e100
singular = np.diag([1., 1., 1., 0.])
matrices = np.stack([small, large, singular])
with np.errstate(over="ignore", under="ignore"):
ordinary = np.linalg.det(matrices)
sign, log_abs = np.linalg.slogdet(matrices)
assert ordinary[0] == 0. and np.isposinf(ordinary[1])
assert ordinary[2] == 0.
assert sign.tolist() == [1., 1., 0.]
assert np.allclose(log_abs[:2], [-400 * np.log(10), 400 * np.log(10)])
assert np.isneginf(log_abs[2])
The finite log magnitudes are about -921.034 and +921.034. These numbers fit within float64. The explicitly singular matrix retains the separate pair consisting of sign zero and negative infinity. Warning suppression in the fixture keeps the printed output focused on the expected range limits. A production calculation can handle its warning and invalid-input policy separately.
Save the two parts together
The sign of the determinant also has meaning for a real coordinate transformation. A reflection with diagonal entries -1, 1, and 1 has negative determinant, but its absolute determinant equals one. A log magnitude of zero therefore describes its volume scaling while the sign describes an orientation reversal for that linear map. An identity transform has the same log magnitude and positive sign.
reflection = np.diag([-1., 1., 1.])
reflection_sign, reflection_log = np.linalg.slogdet(reflection)
assert reflection_sign == -1. and reflection_log == 0.
Use separate fields for sign and log magnitude so the result stays interpretable when it leaves the numerical program. A downstream application that immediately takes the exponential to reconstruct the original determinant can encounter the same range problem. Keep computations in the log domain when possible. In a data format that requires finite numbers, represent a singular result with an explicit status and a missing log magnitude, then record the convention for the reader.
Compare covariance only in a consistent representation
For a positive-definite covariance in a given coordinate system, the determinant gives a scale related to the product of the coordinate variances after diagonalization. Changing units changes that determinant. Consider an invented two-axis position covariance with diagonal entries 1e-6 and 4e-6 in squared meters. Converting positions to millimeters multiplies both coordinates by 1000. The full covariance matrix scales by 1e6, so the determinant of this two-dimensional covariance scales by 1e12. The log determinant increases by four times the natural logarithm of 1000.
cov_m = np.diag([1e-6, 4e-6])
cov_mm = cov_m * 1e6
_, log_m = np.linalg.slogdet(cov_m)
_, log_mm = np.linalg.slogdet(cov_mm)
assert np.isclose(log_mm - log_m, 4 * np.log(1000.))
Both matrices describe the same uncertainty in different units. The log difference therefore does not indicate a change in calibration quality. Use a consistent definition of the estimated variables and the same reference units when comparing logs. If the coordinate axes scale by different factors, transform the full covariance according to those factors rather than scaling all elements uniformly.
Keep conditioning as a separate diagnostic
The small and large identity multiples in the first fixture both have a two-norm condition number of one. This condition number is the ratio of the largest to the smallest singular value. Uniform scaling changes both singular values by the same factor. The determinant, however, compounds the change across dimensions. Consequently a very small determinant by itself does not show that the matrix has a poorly observed direction.
A determinant only records the product of the eigenvalues. For example, the two-by-two diagonal matrices with entries [2, 3] and [-2, -3] both have determinant six. The first can be a covariance and the second cannot because its diagonal entries would represent negative variances. In more general examples, inspecting diagonal entries alone is insufficient. Use a test appropriate for the full covariance and keep the determinant as a summary calculated after validating the input. If a singular covariance is allowed by design, preserve that status instead of treating a small finite log magnitude as its substitute.
A finite log determinant also does not certify that a calibration matrix is well conditioned or that a reported covariance is positive definite. Inspect the conditioning, symmetry, and matrix type required by the application. When diagnosing a fit, retain the parameter units and any normalization factors. Regression examples can check an underflow case, an overflow case, an exactly singular case, and a unit conversion separately. That makes it possible to tell whether a changed report reflects the measurement model or the way the program encodes the result.
Sources checked November 28, 2026
NumPy, numpy.linalg.slogdet
https://numpy.org/doc/stable/reference/generated/numpy.linalg.slogdet.html
NumPy, numpy.linalg.det
https://numpy.org/doc/stable/reference/generated/numpy.linalg.det.html
NumPy, numpy.linalg.cond
https://numpy.org/doc/stable/reference/generated/numpy.linalg.cond.html
Illustration. AI-generated concept showing separate sign and log-magnitude fields on a diagnostic display in a robot calibration lab.