Python中连接两个数组

4

我有大小为A (1, 1, 59) 和B (1, 95, 59) 的数组。我想要拼接这两个数组,并使得拼接后的数组大小为(1, 96, 59)

np.concatenate((A, B),axis =0)

无法正常工作,错误为ValueError: all the input array dimensions except for the concatenation axis must match exactly


给我们更多信息,你是指将数组作为列表,对吗?如果是这样,我有一个解决方案。 - Sanjay Pradeep
1个回答

7
轴线不正确:
>>> import numpy as np
>>> A = np.ones((1,1,59))
>>> B = np.zeros((1,56,59))
>>> np.concatenate((A, B), axis=1)
array([[[ 1.,  1.,  1., ...,  1.,  1.,  1.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        ..., 
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.]]])
>>> _.shape
(1, 57, 59)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接