3d numpy数组到2d

我有这样的3d矩阵

arange(16).reshape((4,2,2))
array([[[ 0,  1],
        [ 2,  3]],

        [[ 4,  5],
        [ 6,  7]],

        [[ 8,  9],
        [10, 11]],

        [[12, 13],
        [14, 15]]])

并希望以网格格式堆叠它们,最终以

array([[ 0,  1,  4,  5],
       [ 2,  3,  6,  7],
       [ 8,  9, 12, 13],
       [10, 11, 14, 15]])

有没有一种方式没有明确的堆栈(和/或vstacking)他们或添加额外的维度和重塑(不知道这会工作)?

谢谢,


In [27]: x = np.arange(16).reshape((4,2,2))

In [28]: x.reshape(2,2,2,2).swapaxes(1,2).reshape(4,-1)
Out[28]: 
array([[ 0,  1,  4,  5],
       [ 2,  3,  6,  7],
       [ 8,  9, 12, 13],
       [10, 11, 14, 15]])

在这里,我已经发布了更多用于将数组重新整形/不整形的通用函数。

链接地址: http://www.djcxy.com/p/68099.html

上一篇: 3d Numpy array to 2d

下一篇: Retrieving user's email Google Login iOS