python实现简单的多维shuffle

如何按照shuffle过的idx给元素重新排序

>>> a = np.arange(24).reshape(4,3,2)                                            
>>> idx=numpy.arange(len(a))                                                    
>>> print(idx)
[0 1 2 3]
>>> np.random.shuffle(idx)                                                      
>>> print(idx)                                                                  
[0 2 3 1]
>>> a[idx, ...]                                                                 
array([[[ 0,  1],
        [ 2,  3],
        [ 4,  5]],

       [[12, 13],
        [14, 15],
        [16, 17]],

       [[18, 19],
        [20, 21],
        [22, 23]],

       [[ 6,  7],
        [ 8,  9],
        [10, 11]]])
>>> print(a.shape)                                                              
(4, 3, 2)
>>> a                                                                           
array([[[ 0,  1],
        [ 2,  3],
        [ 4,  5]],

       [[ 6,  7],
        [ 8,  9],
        [10, 11]],

       [[12, 13],
        [14, 15],
        [16, 17]],

       [[18, 19],
        [20, 21],
        [22, 23]]])

你可能感兴趣的:(python实现简单的多维shuffle)