MCPcopy Create free account
hub / github.com/numpy/numpy / slogdet

Function slogdet

numpy/linalg/linalg.py:2038–2123  ·  view source on GitHub ↗

Compute the sign and (natural) logarithm of the determinant of an array. If an array has a very small or very large determinant, then a call to `det` may overflow or underflow. This routine is more robust against such issues, because it computes the logarithm of the determinant rat

(a)

Source from the content-addressed store, hash-verified

2036
2037@array_function_dispatch(_unary_dispatcher)
2038def slogdet(a):
2039 """
2040 Compute the sign and (natural) logarithm of the determinant of an array.
2041
2042 If an array has a very small or very large determinant, then a call to
2043 `det` may overflow or underflow. This routine is more robust against such
2044 issues, because it computes the logarithm of the determinant rather than
2045 the determinant itself.
2046
2047 Parameters
2048 ----------
2049 a : (..., M, M) array_like
2050 Input array, has to be a square 2-D array.
2051
2052 Returns
2053 -------
2054 A namedtuple with the following attributes:
2055
2056 sign : (...) array_like
2057 A number representing the sign of the determinant. For a real matrix,
2058 this is 1, 0, or -1. For a complex matrix, this is a complex number
2059 with absolute value 1 (i.e., it is on the unit circle), or else 0.
2060 logabsdet : (...) array_like
2061 The natural log of the absolute value of the determinant.
2062
2063 If the determinant is zero, then `sign` will be 0 and `logabsdet` will be
2064 -Inf. In all cases, the determinant is equal to ``sign * np.exp(logabsdet)``.
2065
2066 See Also
2067 --------
2068 det
2069
2070 Notes
2071 -----
2072
2073 .. versionadded:: 1.8.0
2074
2075 Broadcasting rules apply, see the `numpy.linalg` documentation for
2076 details.
2077
2078 .. versionadded:: 1.6.0
2079
2080 The determinant is computed via LU factorization using the LAPACK
2081 routine ``z/dgetrf``.
2082
2083
2084 Examples
2085 --------
2086 The determinant of a 2-D array ``[[a, b], [c, d]]`` is ``ad - bc``:
2087
2088 >>> a = np.array([[1, 2], [3, 4]])
2089 >>> (sign, logabsdet) = np.linalg.slogdet(a)
2090 >>> (sign, logabsdet)
2091 (-1, 0.69314718055994529) # may vary
2092 >>> sign * np.exp(logabsdet)
2093 -2.0
2094
2095 Computing log-determinants for a stack of matrices:

Callers

nothing calls this directly

Calls 8

asarrayFunction · 0.90
_assert_stacked_2dFunction · 0.85
_assert_stacked_squareFunction · 0.85
_commonTypeFunction · 0.85
_realTypeFunction · 0.85
isComplexTypeFunction · 0.85
astypeMethod · 0.80
SlogdetResultClass · 0.70

Tested by

no test coverage detected