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)
| 2270 | |
| 2271 | @array_function_dispatch(_unary_dispatcher) |
| 2272 | def slogdet(a): |
| 2273 | """ |
| 2274 | Compute the sign and (natural) logarithm of the determinant of an array. |
| 2275 | |
| 2276 | If an array has a very small or very large determinant, then a call to |
| 2277 | `det` may overflow or underflow. This routine is more robust against such |
| 2278 | issues, because it computes the logarithm of the determinant rather than |
| 2279 | the determinant itself. |
| 2280 | |
| 2281 | Parameters |
| 2282 | ---------- |
| 2283 | a : (..., M, M) array_like |
| 2284 | Input array, has to be a square 2-D array. |
| 2285 | |
| 2286 | Returns |
| 2287 | ------- |
| 2288 | A namedtuple with the following attributes: |
| 2289 | |
| 2290 | sign : (...) array_like |
| 2291 | A number representing the sign of the determinant. For a real matrix, |
| 2292 | this is 1, 0, or -1. For a complex matrix, this is a complex number |
| 2293 | with absolute value 1 (i.e., it is on the unit circle), or else 0. |
| 2294 | logabsdet : (...) array_like |
| 2295 | The natural log of the absolute value of the determinant. |
| 2296 | |
| 2297 | If the determinant is zero, then `sign` will be 0 and `logabsdet` |
| 2298 | will be -inf. In all cases, the determinant is equal to |
| 2299 | ``sign * np.exp(logabsdet)``. |
| 2300 | |
| 2301 | See Also |
| 2302 | -------- |
| 2303 | det |
| 2304 | |
| 2305 | Notes |
| 2306 | ----- |
| 2307 | Broadcasting rules apply, see the `numpy.linalg` documentation for |
| 2308 | details. |
| 2309 | |
| 2310 | The determinant is computed via LU factorization using the LAPACK |
| 2311 | routine ``z/dgetrf``. |
| 2312 | |
| 2313 | Examples |
| 2314 | -------- |
| 2315 | The determinant of a 2-D array ``[[a, b], [c, d]]`` is ``ad - bc``: |
| 2316 | |
| 2317 | >>> import numpy as np |
| 2318 | >>> a = np.array([[1, 2], [3, 4]]) |
| 2319 | >>> (sign, logabsdet) = np.linalg.slogdet(a) |
| 2320 | >>> (sign, logabsdet) |
| 2321 | (-1, 0.69314718055994529) # may vary |
| 2322 | >>> sign * np.exp(logabsdet) |
| 2323 | -2.0 |
| 2324 | |
| 2325 | Computing log-determinants for a stack of matrices: |
| 2326 | |
| 2327 | >>> a = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ]) |
| 2328 | >>> a.shape |
| 2329 | (3, 2, 2) |
nothing calls this directly
no test coverage detected
searching dependent graphs…