Compute the determinant of an array. Parameters ---------- a : (..., M, M) array_like Input array to compute determinants for. Returns ------- det : (...) array_like Determinant of `a`. See Also -------- slogdet : Another way to represent t
(a)
| 2354 | |
| 2355 | @array_function_dispatch(_unary_dispatcher) |
| 2356 | def det(a): |
| 2357 | """ |
| 2358 | Compute the determinant of an array. |
| 2359 | |
| 2360 | Parameters |
| 2361 | ---------- |
| 2362 | a : (..., M, M) array_like |
| 2363 | Input array to compute determinants for. |
| 2364 | |
| 2365 | Returns |
| 2366 | ------- |
| 2367 | det : (...) array_like |
| 2368 | Determinant of `a`. |
| 2369 | |
| 2370 | See Also |
| 2371 | -------- |
| 2372 | slogdet : Another way to represent the determinant, more suitable |
| 2373 | for large matrices where underflow/overflow may occur. |
| 2374 | scipy.linalg.det : Similar function in SciPy. |
| 2375 | |
| 2376 | Notes |
| 2377 | ----- |
| 2378 | Broadcasting rules apply, see the `numpy.linalg` documentation for |
| 2379 | details. |
| 2380 | |
| 2381 | The determinant is computed via LU factorization using the LAPACK |
| 2382 | routine ``z/dgetrf``. |
| 2383 | |
| 2384 | Examples |
| 2385 | -------- |
| 2386 | The determinant of a 2-D array [[a, b], [c, d]] is ad - bc: |
| 2387 | |
| 2388 | >>> import numpy as np |
| 2389 | >>> a = np.array([[1, 2], [3, 4]]) |
| 2390 | >>> np.linalg.det(a) |
| 2391 | -2.0 # may vary |
| 2392 | |
| 2393 | Computing determinants for a stack of matrices: |
| 2394 | |
| 2395 | >>> a = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ]) |
| 2396 | >>> a.shape |
| 2397 | (3, 2, 2) |
| 2398 | >>> np.linalg.det(a) |
| 2399 | array([-2., -3., -8.]) |
| 2400 | |
| 2401 | """ |
| 2402 | a = asarray(a) |
| 2403 | _assert_stacked_square(a) |
| 2404 | t, result_t = _commonType(a) |
| 2405 | signature = 'D->D' if isComplexType(t) else 'd->d' |
| 2406 | r = _umath_linalg.det(a, signature=signature) |
| 2407 | r = r.astype(result_t, copy=False) |
| 2408 | return r |
| 2409 | |
| 2410 | |
| 2411 | # Linear Least Squares |