slogdet(a)
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 rather than the determinant itself.
Broadcasting rules apply, see the numpy.linalg
documentation for details.
The determinant is computed via LU factorization using the LAPACK routine z/dgetrf
.
Input array, has to be a square 2-D array.
A number representing the sign of the determinant. For a real matrix, this is 1, 0, or -1. For a complex matrix, this is a complex number with absolute value 1 (i.e., it is on the unit circle), or else 0.
The natural log of the absolute value of the determinant.
Compute the sign and (natural) logarithm of the determinant of an array.
The determinant of a 2-D array [[a, b], [c, d]]
is ad - bc
:
>>> a = np.array([[1, 2], [3, 4]])
... (sign, logdet) = np.linalg.slogdet(a)
... (sign, logdet) (-1, 0.69314718055994529) # may vary
>>> sign * np.exp(logdet) -2.0
Computing log-determinants for a stack of matrices:
>>> a = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ])
... a.shape (3, 2, 2)
>>> sign, logdet = np.linalg.slogdet(a)
... (sign, logdet) (array([-1., -1., -1.]), array([ 0.69314718, 1.09861229, 2.07944154]))
>>> sign * np.exp(logdet) array([-2., -3., -8.])
This routine succeeds where ordinary det
does not:
>>> np.linalg.det(np.eye(500) * 0.1) 0.0
>>> np.linalg.slogdet(np.eye(500) * 0.1) (1, -1151.2925464970228)See :
The following pages refer to to this document either explicitly or contain code examples using this.
numpy.linalg.det
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them