How to reshape () the sum of odd and even rows in numpy

前端 未结 2 1722
独厮守ぢ
独厮守ぢ 2021-01-25 10:49

Example1 :

a = np.array([[[1,11,111],[2,22,222]],
              [[3,33,333],[4,44,444]],
              [[5,55,555],[6,66,666]],[[7,77,777],[8,88,888]]])

>>         


        
相关标签:
2条回答
  • 2021-01-25 11:35
    >>> np.array(list(zip(*a))).reshape(2,12)
    array([[  1,  11, 111,   3,  33, 333,   5,  55, 555,   7,  77, 777],
           [  2,  22, 222,   4,  44, 444,   6,  66, 666,   8,  88, 888]])
    
    0 讨论(0)
  • 2021-01-25 11:38

    Permute axes and reshape to 2D -

    In [14]: a
    Out[14]: 
    array([[[  1,  11, 111],
            [  2,  22, 222]],
    
           [[  3,  33, 333],
            [  4,  44, 444]],
    
           [[  5,  55, 555],
            [  6,  66, 666]],
    
           [[  7,  77, 777],
            [  8,  88, 888]]])
    
    In [15]: a.swapaxes(0,1).reshape(a.shape[1],-1)
    Out[15]: 
    array([[  1,  11, 111,   3,  33, 333,   5,  55, 555,   7,  77, 777],
           [  2,  22, 222,   4,  44, 444,   6,  66, 666,   8,  88, 888]])
    
    0 讨论(0)
提交回复
热议问题