2

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 ?

Eric H.
  • 2,152
  • 4
  • 22
  • 34
  • 4
    `lstsq` is _designed_ to give you a response even if the system of equations is undetermined... You may want to look also at `X[3]`, that lists the _singular values_ of the coefficients matrix. – gboffi Nov 27 '14 at 10:26

0 Answers0