shuffle函数测试

it2025-09-25  2

import random import numpy as np a = [[0,1],[2,3],[4,5],[6,7],[8,9]] print 'origin:', a random.shuffle(a) print 'shuffled:', a ### 结果 # origin: [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]] # shuffled: [[8, 9], [2, 3], [0, 1], [4, 5], [6, 7]] a = [[[0,1],[2,3]],[[4,5],[6,7]],[[8,9],[10, 11]]] a = np.array(a) print a print a.shape np.random.shuffle(a) print a # This function only shuffles the array along the first index of a multi-dimensional array #(多维矩阵中,只对第一维(行)做打乱顺序操作) # (3, 2, 2) # origin -> # shuffled #[[[ 0 1] -> #[[[ 0 1] # [ 2 3]] -> # [ 2 3]] # [[ 4 5] -> # [[ 8 9] # [ 6 7]] -> # [10 11]] # [[ 8 9] -> # [[ 4 5] # [10 11]]] -> # [ 6 7]]]
最新回复(0)