我有两个如下数组:
ss3 = [[0 1 2 3 4 5]
[0 1 2 3 4 5]
[0 1 2 3 4 5]]
ss1 = [[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]]
我如何加入他们,所以输出看起来像这样:
s = [[0 1 2 3 4 5][0 1 2 3 4 5][0 1 2 3 4 5][0][0][0][0][0][0][0][0][0]]
我尝试过:
s = np.concatenate(ss3,ss1,axis=0)
但是请继续获取错误:
ValueError: all the input array dimensions except for the concatenation axis must match exactly
答案 0 :(得分:2)
如果它们只是数组,则可以使用:
ss3 = [[0, 1, 2, 3, 4, 5],[0, 1, 2, 3, 4, 5],[0, 1, 2, 3, 4, 5]]
ss1 = [[0],[0],[0],[0],[0],[0],[0],[0],[0]]
merged = ss3+ss1
哪个给:
[[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0], [0], [0], [0], [0], [0], [0], [0], [0]]
答案 1 :(得分:0)
根据@Andrew,您也可以使用extend
ss3 = [[0, 1, 2, 3, 4, 5],[0, 1, 2, 3, 4, 5],[0, 1, 2, 3, 4, 5]]
ss1 = [[0],[0],[0],[0],[0],[0],[0],[0],[0]]
newArray = []
newArray.extend(ss3)
newArray.extend(ss1)
print newArray