慕容3067478
有两种可能的结果重排(以下为@eumiro的示例)。Einops软件包提供了强有力的注释来明确描述此类操作>> a = np.arange(18).reshape(9,2)# this version corresponds to eumiro's answer>> einops.rearrange(a, '(x y) z -> z y x', x=3)array([[[ 0, 6, 12], [ 2, 8, 14], [ 4, 10, 16]], [[ 1, 7, 13], [ 3, 9, 15], [ 5, 11, 17]]])# this has the same shape, but order of elements is different (note that each paer was trasnposed)>> einops.rearrange(a, '(x y) z -> z x y', x=3)array([[[ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]], [[ 1, 3, 5], [ 7, 9, 11], [13, 15, 17]]])