title: How to invert numpy matrices using Singular Value Decomposition?
body: <p>(Before you tell me, yes, I know you should <em>never</em> invert the matrix. Unfortunately for my calculations, I have a matrix which I have constructed, and it must be inverted somehow.)</p>
  
  <p>I have a large matrix <code>M</code> which is ill-conditioned. <code>numpy.linalg.cond(M)</code> outputs a value of magnitude <code>e+22</code>. The matrix <code>M</code> is shaped <code>(1000,1000)</code>. </p>
  
  <p>Naturally, <code>numpy.linalg.inv()</code> will result in many precision errors. So, I have used <code>numpy.linalg.solve()</code> to invert the matrix. </p>
  
  <p>Consider that the matrix inverse <code>A^{-1}</code> is defined by <code>A * A^{-1} = Identity</code>. 
  <code>numpy.linalg.solve()</code> computes the “exact” solution, x, of the well-determined, i.e., full rank, linear matrix equation ax = b.</p>
  
  <p>So, I define the identity matrix:</p>
  
  <pre><code>import numpy as np
  iddmatrix = np.identity(100)
  </code></pre>
  
  <p>and solve:</p>
  
  <pre><code>inverse = np.linalg.solve(M, iddmatrix)
  </code></pre>
  
  <p>However, because my matrix is <em>so</em> large and <em>so</em> ill-conditioned, <code>np.linalg.solve()</code> will not give the "exact solution". I need another method to invert the matrix. </p>
  
  <ol>
  <li>What is the standard way to implement such an inverse with SVD?</li>
  <li>How could I make this ill-conditioned matrix....well-defined?</li>
  </ol>
  
  <p>Any recommendations are appreciated. Thanks!</p>