# 默认按照第0维度进行排序 lables, datas = [list(x) for x inzip(*sorted(zip(labels, datas)))] # 若要指定特定维度 from operator import itemgetter datas, labels = [list(x) for x inzip(*sorted(zip(datas, labels), key=itemgetter(1)))]
额外介绍我的愚蠢实现思路:
用 $index/length$ 作为小数位添加到 $labelList$ 上
$SORT$ 排序列表,分离并复原Index
基于Index对列表进行排序赋值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
defsort_dataset(dataset): # the num_new_class can be calculate by some formula, but in this part make it HARD # sort those data and label which make it easier to del class. num_data = len(dataset) up_limit = pow(10, len(str(num_data))) index = [index /up_limit for index in num_data]
# using this mark to sort the data for i, _ inenumerate(dataset.targets): dataset.targets[i] += index[i] dataset.targets.sort()
# get the new order new_order = [target - int(target) for target in dataset.targets] * up_limit dataset.targets = [int(target) for target in dataset.targets] # it's necessary for us to swith to list or not? dataset.data = list(np.array(dataset.data)[new_order])