title: Large memory usage of scipy.sparse.csr_matrix.toarray()
body: <p>I have a fairly large sparse matrix <code>A</code> as a <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.html" rel="nofollow noreferrer">scipy.sparse.csr_matrix</a>. It has the following properties:</p>
  
  <pre><code>A.shape: (77169, 77169)
  A.nnz: 284811011
  A.dtype: dtype('float16')
  </code></pre>
  
  <p>Now I have to convert it to a dense array using <code>.toarray()</code>. My estimate for the memory usage would be</p>
  
  <pre><code>77169**2 * (16./8.) / 1024.**3 = 11.09... GB
  </code></pre>
  
  <p>which would be fine as my machine has ~48GB of memory. In fact, if I create <code>a=np.ones((77169, 77169), dtype=np.float16)</code> that works fine and indeed <code>a.nbytes/1024.**3 = 11.09...</code>. However, when I run <code>A.toarray()</code> on the sparse matrix it packs all of memory and starts to use the swap at some point (it doesn't raise a <code>MemoryError</code>). Whats going wrong here? Shouldn't it easily fit into my memory?</p>