title: What is the fastest way to extract given rows and columns from a Numpy ndarray?
body: <p>I have a large (approx. 14,000 x 14,000) square matrix represented as a Numpy <code>ndarray</code>. I wish to extract a large number of rows and columns--the indices of which I know in advance, though it will in fact be all rows and columns that are not all-zero--to get a new square matrix (approx 10,000 x 10,000).</p>
  
  <p>The fastest way I have found to do this is:</p>
  
  <pre><code>&gt; timeit A[np.ix_(indices, indices)]
  1 loops, best of 3: 6.19 s per loop
  </code></pre>
  
  <p>However, this is much slower than the time it takes to do matrix multiplication:</p>
  
  <pre><code>&gt; timeit np.multiply(A, A)
  1 loops, best of 3: 982 ms per loop
  </code></pre>
  
  <p>This seems strange, since both the row/column extraction and matrix multiplication need to allocate a new array (which will be even larger for the result of the matrix multiplication than for the extraction), but matrix multiplication also needs to perform additional computation.</p>
  
  <p>Thus, the question: is there a more efficient way to perform the extraction, in particular, that is at least as fast as matrix multiplication?</p>