Interleave rows of two numpy arrays in Python

后端 未结 3 1788
鱼传尺愫
鱼传尺愫 2021-01-17 09:51

I wanted to interleave the rows of two numpy arrays of the same size. I came up with this solution.

# A and B are same-shaped arrays
A = numpy.ones((4,3))
B         


        
3条回答
  •  天命终不由人
    2021-01-17 10:03

    You can stack, transpose, and reshape:

    numpy.dstack((A, B)).transpose(0, 2, 1).reshape(A.shape[0]*2, A.shape[1])
    

提交回复
热议问题