假设我有两个数组a和b。
a.shape is (95, 300)
b.shape is (95, 3)
我该如何通过将这95行连接起来来获得一个新的数组c?
c.shape is (95, 303)
如果我理解正确,您可以使用hstack
函数:
>>> a = np.ones((95, 300))
>>> b = np.ones((95, 3)) * 2
>>> a.shape
(95, 300)
>>> b.shape
(95, 3)
>>> c = np.hstack((a,b))
>>> c
array([[ 1., 1., 1., ..., 2., 2., 2.],
[ 1., 1., 1., ..., 2., 2., 2.],
[ 1., 1., 1., ..., 2., 2., 2.],
...,
[ 1., 1., 1., ..., 2., 2., 2.],
[ 1., 1., 1., ..., 2., 2., 2.],
[ 1., 1., 1., ..., 2., 2., 2.]])
>>> c.shape
(95, 303)