In python numpy least squares, why a singular normal matrix does NOT raise LinAlgError?

345 views Asked by At

Solving A.X = B by least squares. Given this :

import numpy as np
A=[[1,0],[0,0]]
B=[1,0]
X=np.linalg.lstsq(A, B)     # X = 1/(At.A) * (At.B)
print X[0]  # [ 1.  0.]

At.A is A, and det(A)=0 --> singular. So there is an infinity of solutions; [1,0] is one.

Why lstsq doesn't raise np.linalg.linalg.LinAlgError ? The doc says "If computation does not converge.". Is not that the case ?

Does anyone have a simple example where this exception is raised with lstsq ?

0

There are 0 answers