linalg.det throws LinAlgError for 0-by-0 matrices
See original GitHub issueSince LAPACK functions cannot handle 0-by-0 matrices, numpy must explicitly handle those cases. However, while in newer versions of numpy, the inverse is computed correctly, the determinant raises LinAlgError
:
>>> A = numpy.empty((0, 0))
>>> numpy.linalg.inv(A)
array([], shape=(0, 0), dtype=float64)
>>> numpy.linalg.det(A)
LinAlgError: Arrays cannot be empty
Since the determinant of a zero-by-zero matrix is well-defined, a LinAlgError is IMHO wrong, since it indicates a numerics problem rather than the purely technical fact that the backend cannot handle this.
Thus, expected result:
>>> numpy.linalg.det(A)
1.0
Numpy version: 1.11.0 (also present in git master) Python version: 2.7.12
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
How to Fix: numpy.linalg.LinAlgError: Singular matrix - Statology
By definition, a matrix is singular and cannot be inverted if it has a determinant of zero. You can use the det() function...
Read more >numpy.linalg.LinAlgError: Singular matrix Error When Trying to ...
This is not IDE dependent. Your A matrix is singular, with one of its singular values equal to zero. That means its determinant...
Read more >numpy.linalg.det — NumPy v1.24 Manual
numpy.linalg.det#. linalg.det(a)[source]#. Compute the determinant of an array. Parameters: a(…, M, M) array_like. Input array to compute determinants for.
Read more >Sage Reference Manual: Matrices and Spaces of Matrices
Note: Linear algebra in Sage favors rows over columns. ... -59 -109 304]sage: det(A)1A matrix size 6 with entries no larger than 50.sage: ......
Read more >scipy.linalg.det — SciPy v1.9.3 Manual
The determinant of a square matrix is a value derived arithmetically from the coefficients of the matrix. The determinant for a 3x3 matrix,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All “stacked” arrays are always of the same shape, which can be determined from the overall shape so no loops needed.
@ashwinpathak20:
This is already well in process (#8368),but has opened a can of worms:#8369 - the tests weren’t testing this type of array properly#8381 - the tools for rebundling lapack were also brokenUpdate: mostly fixed!