Flatten or group array in blocks of columns - NumPy / Python

前端 未结 6 677
醉酒成梦
醉酒成梦 2020-12-04 03:00

Is there any easy way to flatten

import numpy    
np.arange(12).reshape(3,4)
Out[]: 
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11         


        
6条回答
  •  星月不相逢
    2020-12-04 03:44

    For this I'd simply slice and concatenate:

    n = a.shape[1]//2
    np.concatenate([a[:,:n], a[:,n:]]).ravel()
    # array([ 0,  1,  4,  5,  8,  9,  2,  3,  6,  7, 10, 11])
    

提交回复
热议问题