Be aware that random.shuffle()
should not be used on multi-dimensional arrays as it causes repetitions.
Imagine you want to shuffle an array along its first dimension, we can create the following test example,
import numpy as np
x = np.zeros((10, 2, 3))
for i in range(10):
x[i, ...] = i*np.ones((2,3))
so that along the first axis, the i-th element corresponds to a 2x3 matrix where all the elements are equal to i.
If we use the correct shuffle function for multi-dimensional arrays, i.e. np.random.shuffle(x)
, the array will be shuffled along the first axis as desired. However, using random.shuffle(x)
will cause repetitions. You can check this by running len(np.unique(x))
after shuffling which gives you 10 (as expected) with np.random.shuffle()
but only around 5 when using random.shuffle()
.