Shuffle an array with python, randomize array item order with python Shuffle an array with python, randomize array item order with python python python

Shuffle an array with python, randomize array item order with python


import randomrandom.shuffle(array)


import randomrandom.shuffle(array)


Alternative way to do this using sklearn

from sklearn.utils import shuffleX=[1,2,3]y = ['one', 'two', 'three']X, y = shuffle(X, y, random_state=0)print(X)print(y)

Output:

[2, 1, 3]['two', 'one', 'three']

Advantage: You can random multiple arrays simultaneously without disrupting the mapping. And 'random_state' can control the shuffling for reproducible behavior.


matomo