title: Numpy: shuffle arrays in unison multiple times with different seeds
body: <p>I have multiple numpy arrays with the same number of rows (axis_0) that I'd like to shuffle in unison. After one shuffle, I'd like to shuffle them again with a different random seed.</p>
  
  <hr/>
  
  <p>Till now, I've used the solution from
  <a href="https://stackoverflow.com/questions/4601373/better-way-to-shuffle-two-numpy-arrays-in-unison">Better way to shuffle two numpy arrays in unison</a> :</p>
  
  <pre><code>def shuffle_in_unison(a, b):
      rng_state = numpy.random.get_state()
      numpy.random.shuffle(a)
      numpy.random.set_state(rng_state)
      numpy.random.shuffle(b)
  </code></pre>
  
  <p>However, this doesn't work for multiple unison shuffles, since <code>rng_state</code> is always the same.
  <hr/>
  I've tried to use <code>RandomState</code> in order to get a different seed for each call, but this doesn't even work for a single unison shuffle:</p>
  
  <pre><code>a = np.array([1,2,3,4,5])
  b = np.array([10,20,30,40,50])
  
  def shuffle_in_unison(a, b):
      r = np.random.RandomState() # different state from /dev/urandom for each call
      state = r.get_state()
      np.random.shuffle(a) # array([4, 2, 1, 5, 3])
      np.random.set_state(state)
      np.random.shuffle(b) # array([40, 20, 50, 10, 30])
      # -&gt; doesn't work
      return a,b
  
  for i in xrange(10):
      a,b = shuffle_in_unison(a,b)
      print a,b
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <hr/>
  
  <hr/>
  
  <p><strong>Edit:</strong> </p>
  
  <p>For everyone that doesn't have huge arrays like me, just use the solution by Francesco (<a href="https://stackoverflow.com/a/47156309/3955022">https://stackoverflow.com/a/47156309/3955022</a>):</p>
  
  <pre><code>def shuffle_in_unison(a, b):
      n_elem = a.shape[0]
      indeces = np.random.permutation(n_elem)
      return a[indeces], b[indeces]
  </code></pre>
  
  <p>The only drawback is that this is not an in-place operation, which is a pity for large arrays like mine (500G).</p>