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)
| 2125 | |
| 2126 | @array_function_dispatch(_unary_dispatcher) |
| 2127 | def det(a): |
| 2128 | """ |
| 2129 | Compute the determinant of an array. |
| 2130 | |
| 2131 | Parameters |
| 2132 | ---------- |
| 2133 | a : (..., M, M) array_like |
| 2134 | Input array to compute determinants for. |
| 2135 | |
| 2136 | Returns |
| 2137 | ------- |
| 2138 | det : (...) array_like |
| 2139 | Determinant of `a`. |
| 2140 | |
| 2141 | See Also |
| 2142 | -------- |
| 2143 | slogdet : Another way to represent the determinant, more suitable |
| 2144 | for large matrices where underflow/overflow may occur. |
| 2145 | scipy.linalg.det : Similar function in SciPy. |
| 2146 | |
| 2147 | Notes |
| 2148 | ----- |
| 2149 | |
| 2150 | .. versionadded:: 1.8.0 |
| 2151 | |
| 2152 | Broadcasting rules apply, see the `numpy.linalg` documentation for |
| 2153 | details. |
| 2154 | |
| 2155 | The determinant is computed via LU factorization using the LAPACK |
| 2156 | routine ``z/dgetrf``. |
| 2157 | |
| 2158 | Examples |
| 2159 | -------- |
| 2160 | The determinant of a 2-D array [[a, b], [c, d]] is ad - bc: |
| 2161 | |
| 2162 | >>> a = np.array([[1, 2], [3, 4]]) |
| 2163 | >>> np.linalg.det(a) |
| 2164 | -2.0 # may vary |
| 2165 | |
| 2166 | Computing determinants for a stack of matrices: |
| 2167 | |
| 2168 | >>> a = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ]) |
| 2169 | >>> a.shape |
| 2170 | (3, 2, 2) |
| 2171 | >>> np.linalg.det(a) |
| 2172 | array([-2., -3., -8.]) |
| 2173 | |
| 2174 | """ |
| 2175 | a = asarray(a) |
| 2176 | _assert_stacked_2d(a) |
| 2177 | _assert_stacked_square(a) |
| 2178 | t, result_t = _commonType(a) |
| 2179 | signature = 'D->D' if isComplexType(t) else 'd->d' |
| 2180 | r = _umath_linalg.det(a, signature=signature) |
| 2181 | r = r.astype(result_t, copy=False) |
| 2182 | return r |
| 2183 | |
| 2184 |