Compute the sign and (natural) logarithm of the determinant of an array.
If an array has a very small or very large determinant, than a call to det may overflow or underflow. This routine is more robust against such issues, because it computes the logarithm of the determinant rather than the determinant itself.
Parameters : | a : array_like
|
---|---|
Returns : | sign : float or complex
logdet : float
If the determinant is zero, then `sign` will be 0 and `logdet` will be : -Inf. In all cases, the determinant is equal to ``sign * np.exp(logdet)``. : |
See also
Notes
The determinant is computed via LU factorization using the LAPACK routine z/dgetrf.
New in version 1.6.0..
Examples
The determinant of a 2-D array [[a, b], [c, d]] is ad - bc:
>>> a = np.array([[1, 2], [3, 4]])
>>> (sign, logdet) = np.linalg.slogdet(a)
>>> (sign, logdet)
(-1, 0.69314718055994529)
>>> sign * np.exp(logdet)
-2.0
This routine succeeds where ordinary det does not:
>>> np.linalg.det(np.eye(500) * 0.1)
0.0
>>> np.linalg.slogdet(np.eye(500) * 0.1)
(1, -1151.2925464970228)