fork download
  1. import numpy as np
  2.  
  3. r, c = 3, 4 # x.shape
  4.  
  5. x = np.arange(12) + 1 # Already raveled
  6. inds = np.arange(x.size)
  7. rows = np.repeat(np.arange(r).reshape(-1, 1), c, axis=1).ravel()
  8.  
  9. np.random.shuffle(inds)
  10. x = x[inds]
  11. rows = rows[inds]
  12.  
  13. inds = np.argsort(rows, kind='mergesort')
  14. x = x[inds].reshape(r, c)
  15.  
  16. print(x)
Success #stdin #stdout 0.14s 25128KB
stdin
Standard input is empty
stdout
[[ 2  4  1  3]
 [ 6  8  7  5]
 [10  9 12 11]]