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

后端 未结 3 880
伪装坚强ぢ
伪装坚强ぢ 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:27

    You can do something like this.

    import numpy as np
    
    x = np.random.randint(100, size=(5, 4))
    y = [16, 15, 12, 12, 17]
    
    print(x)
    
    val = np.concatenate((x,np.reshape(y,(x.shape[0],1))),axis=1)
    print(val)
    

    This outputs:

    [[32 37 35 53]
     [64 23 95 76]
     [17 76 11 30]
     [35 42  6 80]
     [61 88  7 56]]
    
    [[32 37 35 53 16]
     [64 23 95 76 15]
     [17 76 11 30 12]
     [35 42  6 80 12]
     [61 88  7 56 17]]
    

提交回复
热议问题