我有两个形状的 numpy 数组
(129873, 12)
(129873,)
我想将它们连接起来,使它们的形状为:
(129873, 13)
我尝试过 numpy.concatenate
和 numpy.vstack
但似乎出现错误:
ValueError: all the input arrays must have same number of dimensions
关于如何做到这一点有什么建议吗?
最佳答案
我认为这已经在这里得到了回答:
Numpy: Concatenating multidimensional and unidimensional arrays
import numpy
a = numpy.array([[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]])
b = numpy.array([5, 6, 6])
c = numpy.column_stack((a,b))
print a
print b
print c
print a.shape
print b.shape
print c.shape
这给你:
[[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]]
[5 6 6]
[[1 2 3 4 5 5]
[1 2 3 4 5 6]
[1 2 3 4 5 6]]
(3, 5)
(3,)
(3, 6)
关于python - 连接两个numpy数组问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38252109/