In [1]:
import numpy as np
import gc
In [2]:
def simultaneous_shuffle(X, Y):
merged_data = list(zip(X, Y))
np.random.shuffle(merged_data)
X, Y = zip(*merged_data)
del merged_data
gc.collect()
return np.asarray(X), np.asarray(Y)
In [3]:
X = [[1, 5], [6, 7], [4,2]]
Y = [[0, 0], [1, 0], [1,1]]
In [4]:
print(simultaneous_shuffle(X, Y))
In [5]:
from sklearn.utils import shuffle
In [6]:
print(shuffle(X, Y, random_state=1024))
In [7]:
print ("X = ", X)
print ("Y = ", Y)
np.random.shuffle(X)
np.random.shuffle(Y)
print ("Shuffled X = ",X)
print ("Shuffled Y = ",Y)
In [ ]: