I am trying to obtain the left inverse of a non-square matrix in python using either numpy or scipy. How can I translate the following Matlab code to Python?
>> A = [0,1; 0,1; 1,0]
A =
0 1
0 1
1 0
>> y = [2;2;1]
y =
2
2
1
>> A\y
ans =
1.0000
2.0000
Is there a numpy or scipy equivalent of the left inverse \
operator in Matlab?
Use linalg.lstsq(A,y)
since A
is not square. See here for details. You can use linalg.solve(A,y)
if A
is square, but not in your case.