title: Obtaining an invertible square matrix from a non-square matrix of full rank in numpy or matlab
body: <p>Assume you have an <code>NxM</code> matrix <code>A</code> of full rank, where <code>M&gt;N</code>. If we denote the columns by <code>C_i</code> (with dimensions <code>Nx1</code>), then we can write the matrix as </p>
  
  <pre><code>A = [C_1, C_2, ..., C_M]
  </code></pre>
  
  <p>How can you obtain the first linearly independent columns of the original matrix <code>A</code>, so that you can construct a new <code>NxN</code> matrix <code>B</code> that is an invertible matrix with a non-zero determinant. </p>
  
  <pre><code>B = [C_i1, C_i2, ..., C_iN]
  </code></pre>
  
  <p>How can you find the indices <code>{i1, i2, ..., iN}</code> either in matlab or python numpy? Can this be done using singular value decomposition? Code snippets will be very welcome.</p>
  
  <p>EDIT:
  To make this more concrete, consider the following python code</p>
  
  <pre><code>from numpy import *
  from numpy.linalg.linalg import det
  
  M = [[3, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 0, 0, 1], 
       [0, 2, 0, 0, 0]]
  M = array(M)
  
  I = [0,1,2,4]
  assert(abs(det(M[:,I])) &gt; 1e-8)
  </code></pre>
  
  <p>So given a matrix M, one would need to find the indices of a set of <code>N</code> linearly independent column vectors.</p>