3

In Matlab, using the inv() function is often discouraged due to numerical instability (see description section in http://www.mathworks.com/help/matlab/ref/inv.html). It is suggested to replace an expression like:

inv(A)*B 

(where both A and B are matrices), with:

A\B

This becomes critical when the inverted matrix A is close to singular.

Is there a nice way to write this in numpy / scipy? (would solve() work?)

Amro
  • 123,847
  • 25
  • 243
  • 454
Tomer Levinboim
  • 992
  • 12
  • 18
  • 7
    See this Stackoverflow question - [Left inverse in numpy](http://stackoverflow.com/questions/2250403/left-inverse-in-numpy-or-scipy) – mtadd Jun 16 '13 at 19:09
  • 1
    `linalg.solve()` is the correct way to do this - see http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html#numpy.linalg.solve . I believe it's numerically more stable than the inverse (using LU decomposition). – Floris Jun 17 '13 at 02:25

1 Answers1

1

As mentioned in the comments, you need to use the left inverse.

This is described in this question.

To summarize (imitatio, aemulatio):

Community
  • 1
  • 1
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122