summaryrefslogtreecommitdiff
path: root/numpy/linalg/linalg.py
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2013-04-08 23:46:59 +0300
committerPauli Virtanen <pav@iki.fi>2013-04-10 22:47:44 +0300
commit5b0fead2d4e3cc6c82761aba09f330147435a0cf (patch)
treebd6b0312f6494b3d972c0f5e3b14fa80bfef84f5 /numpy/linalg/linalg.py
parent2e8b24e30345c75eb9101ea29e96c9fde48add7f (diff)
downloadnumpy-5b0fead2d4e3cc6c82761aba09f330147435a0cf.tar.gz
ENH: linalg: use _umath_linalg for det()
Diffstat (limited to 'numpy/linalg/linalg.py')
-rw-r--r--numpy/linalg/linalg.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py
index f1568875a..7da35755f 100644
--- a/numpy/linalg/linalg.py
+++ b/numpy/linalg/linalg.py
@@ -1717,6 +1717,9 @@ def slogdet(a):
Notes
-----
+ Broadcasting rules apply, see the `numpy.linalg` documentation for
+ details.
+
The determinant is computed via LU factorization using the LAPACK
routine z/dgetrf.
@@ -1773,12 +1776,12 @@ def det(a):
Parameters
----------
- a : (M, M) array_like
- Input array.
+ a : (..., M, M) array_like
+ Input array to compute determinants for.
Returns
-------
- det : float
+ det : (...) array_like
Determinant of `a`.
See Also
@@ -1799,9 +1802,21 @@ def det(a):
>>> np.linalg.det(a)
-2.0
+ Computing determinants for a stack of matrices:
+
+ >>> a = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ])
+ >>> a.shape
+ (2, 2, 2
+ >>> np.linalg.det(a)
+ array([-2., -3., -8.])
+
"""
- sign, logdet = slogdet(a)
- return sign * exp(logdet)
+ a = asarray(a)
+ _assertNonEmpty(a)
+ _assertRankAtLeast2(a)
+ _assertNdSquareness(a)
+ t, result_t = _commonType(a)
+ return _umath_linalg.det(a.astype(t)).astype(result_t)
# Linear Least Squares