标签:code pre shuff python index rand led print int
import numpy as np
#导入numpy库
def shuffleData(data):
index=np.arange(len(data))
#生成一个数据集行数大小的顺序数组[0,1,...,len(data)](顺序下标)
np.random.shuffle(index)
#打乱顺序下标
data=data[index]
#按照乱序下标重新排列数据集
return data
data=np.arange(18)
data.resize((6,3))
#生成一个4*2的数据集
print("orign:\n",data)
data=shuffleData(data)
print("Shuffled:\n",data)
#输出:
# orign:
# [[ 0 1 2]
# [ 3 4 5]
# [ 6 7 8]
# [ 9 10 11]
# [12 13 14]
# [15 16 17]]
# Shuffled:
# [[ 0 1 2]
# [15 16 17]
# [ 3 4 5]
# [ 9 10 11]
# [ 6 7 8]
# [12 13 14]]
标签:code pre shuff python index rand led print int
原文地址:https://www.cnblogs.com/redo19990701/p/11452369.html