随机以相同顺序随机播放来自不同文件的数据和标签 [英] Randomly shuffle data and labels from different files in the same order
本文介绍了随机以相同顺序随机播放来自不同文件的数据和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
l有两个numpy数组,第一个包含数据,第二个包含标签. 我想根据标签对数据进行混洗.换句话说,我该如何以相同的顺序整理标签和数据.
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]
这是否保留改组顺序?
推荐答案
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]
这篇关于随机以相同顺序随机播放来自不同文件的数据和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文