title: How to solve memory error in mtrand.RandomState.choice?
body: <p>I'm trying to sample 1e7 items from 1e5 strings but getting a memory error. It's fine sampling 1e6 items from 1e4 strings. I'm on a 64bit machine with 4GB RAM and don't think I should be reaching any memory limit at 1e7.  Any ideas?</p>
  
  <pre><code>$ python3
  Python 3.3.3 (default, Nov 27 2013, 17:12:35) 
  [GCC 4.8.2] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import numpy as np
  &gt;&gt;&gt; K = 100
  </code></pre>
  
  <p>Works fine with 1e6 :</p>
  
  <pre><code>&gt;&gt;&gt; N = int(1e6)
  &gt;&gt;&gt; np.random.choice(["id%010d"%x for x in range(N//K)], N)
  array(['id0000005473', 'id0000005694', 'id0000004115', ..., 'id0000006958',
         'id0000009972', 'id0000003009'], 
        dtype='&lt;U12')
  </code></pre>
  
  <p>Error with N=1e7 :</p>
  
  <pre><code>&gt;&gt;&gt; N = int(1e7)
  &gt;&gt;&gt; np.random.choice(["id%010d"%x for x in range(N//K)], N)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "mtrand.pyx", line 1092, in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:8229)
  MemoryError
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>I found this question but it seems to be about catching an error like this rather than solving it.</p>
  
  <p><a href="https://stackoverflow.com/questions/19899910/python-not-catching-memoryerror">Python not catching MemoryError</a></p>
  
  <p>I'd be happy with either a solution still using <code>random.choice</code> or a different method to do this.  Thanks.</p>