2

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)?

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

The overwrite_a option seems to be not available in the NumPy function? And yes, I really want to invert the matrix as I need the solution for every single vector (I want to cache the result and provide fast access to the single vectors of the inverse later).
@Michael Right: the numpy function does not provide this option. Out of curiosity, what will you do with the vectors drawn from the inverse?
I am working with kind of an input-output model. A column in the inverse describes the amounts of products that are totally required to produce a single unit of the product that is represented by the respective column. These amounts are used to scale other matrices and indicators to allow supply chain analysis. When there is a request to calculate a set of products, I just jump into the pre-calculated inverse, get the respective columns, and scale them for the results. The inverse is stored on disk and the columns are loaded via memory mapping which is super-fast…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.