question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

linalg.det throws LinAlgError for 0-by-0 matrices

See original GitHub issue

Since 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:closed
  • Created 7 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pvcommented, Nov 5, 2016

All “stacked” arrays are always of the same shape, which can be determined from the overall shape so no loops needed.

0reactions
eric-wiesercommented, Mar 4, 2017

@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
  • #8376 - the current version of lapack bundled with numpy is very out of date, and buggy
  • #8381 - the tools for rebundling lapack were also broken

Update: mostly fixed!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found