How to add an extra column to a NumPy array

前端 未结 17 2082
一个人的身影
一个人的身影 2020-11-22 14:37

Let’s say I have a NumPy array, a:

a = np.array([
    [1, 2, 3],
    [2, 3, 4]
    ])

And I would like to add a column of ze

17条回答
  •  执笔经年
    2020-11-22 15:19

    For me, the next way looks pretty intuitive and simple.

    zeros = np.zeros((2,1)) #2 is a number of rows in your array.   
    b = np.hstack((a, zeros))
    

提交回复
热议问题