Michael
Michael

Reputation: 5072

Invert a matrix in place with NumPy

I have a very big matrix that I want to invert. numpy.linalg.inv works great but is it also possible to do this in place (without allocating a new matrix)?

Upvotes: 2

Views: 906

Answers (1)

Alan
Alan

Reputation: 9620

No. However scipy.linalg.inv gives you roughly this functionality with the overwrite_a option: http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html#scipy.linalg.inv

But why do you want to invert it? This is almost always the wrong thing to do. http://www.johndcook.com/blog/2010/01/19/dont-invert-that-matrix/

Instead, use numpy.linalg.solve and provide stack all your independent vectors into a single matrix so that you can solve them all at one go. Cheaper, and better numerical stability.

http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.linalg.solve.html#numpy.linalg.solve

Upvotes: 4

Related Questions