编程语言
首页 > 编程语言> > python操作

python操作

作者:互联网

1、排序sorted:将数组按某一值排序

def sort_by_target(mnist):
    reorder_train = np.array(sorted([(target, i) for i, target in enumerate(mnist.target[:60000])]))[:, 1]
    reorder_test = np.array(sorted([(target, i) for i, target in enumerate(mnist.target[60000:])]))[:, 1]
    print(reorder_train.shape)
    mnist.data[:60000] = mnist.data[reorder_train]
    mnist.target[:60000] = mnist.target[reorder_train]
    mnist.data[60000:] = mnist.data[reorder_test + 60000]
    mnist.target[60000:] = mnist.target[reorder_test + 60000]

 

标签:target,python,train,60000,mnist,操作,data,reorder
来源: https://www.cnblogs.com/wllwqdeai/p/15018059.html