I have been trying to shuffle all the elements within a two dimensional numpy ndarray
using 3 different methods.
I've tried np.random.shuffle()
, rng.shuffle()
, and rng.permutation()
.
However, all these methods shuffle the elements along the rows, with the exception of rng.shuffle()
which can shuffle along the columns if axis=1
.
Moreover, none of the previous methods actually (changes contents) "cross" shuffles elements from different rows within the array, for example:
a = np.random.randint(0, 10, (3, 3))
> array([[5, 3, 0], # 1
[9, 5, 2], # 2
[5, 0, 6]]) # 3
np.random.shuffle(a)
> array([[5, 0, 6], # 3
[5, 3, 0], # 1
[9, 5, 2]]) # 2
Though an example of the desired output would be something like this:
> array([[5, 5, 0],
[0, 9, 5],
[3, 6, 2]])
Is my desired output possible? And what is the exact different between these 3 methods? I tried reading the docs on random.shuffle()
, rng.shuffle()
, and rng.permutation()
, but it was noncomprehensive.