【发布时间】:2021-09-20 00:53:43
【问题描述】:
我有两个数组,
A = np.array([[1,2,3],[4,5,6]])
b = np.array([100,101])
我想将它们连接起来,以便在右侧添加一列 b,这样我们就有了一个新数组 A | b,它类似于:
1 2 3 100
4 5 6 101
我正在尝试以这种方式连接:
new = np.concatenate((A, b), axis=1)
但我得到下一个错误:
ValueError: all the input arrays must have the same number of dimensions, but the array at index 0 has 2 dimension(s), and the array at index 1 has 1 dimension(s)
如何连接这两个数组?
【问题讨论】:
-
你了解数组的
shape,以及它们各自的维数吗?
标签: python arrays numpy concatenation