title: Create large random boolean matrix with numpy
body: <p>I am trying to create a huge <code>boolean</code> matrix which is randomly filled with <code>True</code> and <code>False</code> with a given probability <code>p</code>. At first I used this code:</p>
  
  <pre><code>N = 30000
  p = 0.1
  np.random.choice(a=[False, True], size=(N, N), p=[p, 1-p])  
  </code></pre>
  
  <p>But sadly it does not seem to terminate for this big <code>N</code>. So I tried to split it up into the generation of the single rows by doing this:   </p>
  
  <pre><code>N = 30000
  p = 0.1
  mask = np.empty((N, N))
  for i in range (N):
       mask[i] = np.random.choice(a=[False, True], size=N, p=[p, 1-p])            
       if (i % 100 == 0):
            print(i)
  </code></pre>
  
  <p>Now, there happens something strange (at least on my device): The first ~1100 rows are very fastly generated - but after it, the code becomes horribly slow. Why is this happening? What do I miss here? Are there better ways to create a big matrix which has <code>True</code> entries with probability <code>p</code> and <code>False</code> entries with probability <code>1-p</code>?</p>
  
  <p><strong>Edit</strong>: As many of you assumed that the RAM will be a problem: As the device which will run the code has almost 500GB RAM, this won't be a problem.</p>