numpy array concatenate: “ValueError: all the input arrays must have same number of dimensions”

后端 未结 3 892
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 08:36

How to concatenate these numpy arrays?

first np.array with a shape (5,4)

[[  6487    400 489580      0]
 [  6488         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 09:25

    There's also np.c_

    >>> a = np.arange(20).reshape(5, 4)
    >>> b = np.arange(-1, -6, -1)
    >>> a
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11],
           [12, 13, 14, 15],
           [16, 17, 18, 19]])                                                                                                                                   
    >>> b                                                                                                                                                       
    array([-1, -2, -3, -4, -5])                                                                                                                                 
    >>> np.c_[a, b]
    array([[ 0,  1,  2,  3, -1],          
           [ 4,  5,  6,  7, -2],                       
           [ 8,  9, 10, 11, -3],                      
           [12, 13, 14, 15, -4],                                
           [16, 17, 18, 19, -5]])
    

提交回复
热议问题