title: Memory Error at Python while converting to array
body: <p>My code is shown below:</p>
  
  <pre><code>from sklearn.datasets import load_svmlight_files
  import numpy as np
  
  perm1 =np.random.permutation(25000)
  perm2 = np.random.permutation(25000)
  
  X_tr, y_tr, X_te, y_te = load_svmlight_files(("dir/file.feat", "dir/file.feat"))
  
  #randomly shuffle data
  X_train = X_tr[perm1,:].toarray()[:,0:2000]
  y_train = y_tr[perm1]&gt;5 #turn into binary problem
  </code></pre>
  
  <p>The code works fine until here, but when I try to convert one more object to an array, my program returns a memory error.</p>
  
  <p>Code:</p>
  
  <pre><code>X_test = X_te[perm2,:].toarray()[:,0:2000]
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>---------------------------------------------------------------------------
  MemoryError                               Traceback (most recent call last)
  &lt;ipython-input-7-31f5e4f6b00c&gt; in &lt;module&gt;()
  ----&gt; 1 X_test = X_test.toarray()
  
  C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\compressed.pyc in toarray(self, order, out)
      788     def toarray(self, order=None, out=None):
      789         """See the docstring for `spmatrix.toarray`."""
  --&gt; 790         return self.tocoo(copy=False).toarray(order=order, out=out)
      791 
      792     ##############################################################
  
  C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\coo.pyc in toarray(self, order, out)
      237     def toarray(self, order=None, out=None):
      238         """See the docstring for `spmatrix.toarray`."""
  --&gt; 239         B = self._process_toarray_args(order, out)
      240         fortran = int(B.flags.f_contiguous)
      241         if not fortran and not B.flags.c_contiguous:
  
  C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\base.pyc in _process_toarray_args(self, order, out)
      697             return out
      698         else:
  --&gt; 699             return np.zeros(self.shape, dtype=self.dtype, order=order)
      700 
      701 
  
  MemoryError: 
  </code></pre>
  
  <p>I'm new in python, and I dont know whether one needs to manually fix the memory error.</p>
  
  <p>Other parts of my code return the same errors (like training with knn or ann).</p>
  
  <p>How can I fix this?</p>