l have two numpy arrays the first one contains data and the second one contains labels. l want to shuffle the data with respect to their labels. In other way, how can l shuffle my labels and data in the same order.
import numpy as np
data=np.genfromtxt("dataset.csv", delimiter=',')
classes=np.genfromtxt("labels.csv",dtype=np.str , delimiter='\t')
x=np.random.shuffle(data)
y=x[classes]
do this preserves the order of shuffling ?
Generate a random order of elements with
np.random.permutation
and simply index into the arraysdata
andclasses
with those -Alternatively you can concatenate the data and labels together, shuffle them and then separate them into input x and label y as shown below: