How to add an extra column to a NumPy array

前端 未结 17 2077
一个人的身影
一个人的身影 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:34

    One way, using hstack, is:

    b = np.hstack((a, np.zeros((a.shape[0], 1), dtype=a.dtype)))
    

提交回复
热议问题