xorbits.numpy.linalg.slogdet#
- xorbits.numpy.linalg.slogdet(a)#
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 rather than the determinant itself.
- 参数
a ((..., M, M) array_like) – Input array, has to be a square 2-D array.
- 返回
A namedtuple with the following attributes
sign ((…) array_like) – 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.
logabsdet ((…) array_like) – The natural log of the absolute value of the determinant.
If the determinant is zero, then sign will be 0 and logabsdet will be
-Inf. In all cases, the determinant is equal to
sign * np.exp(logabsdet)
.
参见
提示
1.8.0(numpy.linalg) 新版功能.
Broadcasting rules apply, see the numpy.linalg documentation for details.
1.6.0(numpy.linalg) 新版功能.
The determinant is computed via LU factorization using the LAPACK routine
z/dgetrf
.实际案例
The determinant of a 2-D array
[[a, b], [c, d]]
isad - bc
:>>> a = np.array([[1, 2], [3, 4]]) >>> (sign, logabsdet) = np.linalg.slogdet(a) >>> (sign, logabsdet) (-1, 0.69314718055994529) # may vary >>> sign * np.exp(logabsdet) -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, logabsdet = np.linalg.slogdet(a) >>> (sign, logabsdet) (array([-1., -1., -1.]), array([ 0.69314718, 1.09861229, 2.07944154])) >>> sign * np.exp(logabsdet) 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)
警告
This method has not been implemented yet. Xorbits will try to execute it with numpy.linalg.
This docstring was copied from numpy.linalg.