Issue
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 ?
Solution
Generate a random order of elements with np.random.permutation
and simply index into the arrays data
and classes
with those -
idx = np.random.permutation(len(data))
x,y = data[idx], classes[idx]
Answered By - Divakar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.