【发布时间】:2014-03-26 13:49:03
【问题描述】:
我有一个生成 numpy 数组的循环:
for x in range(0, 1000):
myArray = myFunction(x)
返回的数组总是一维的。我想将所有数组组合成一个数组(也是一维的。
我尝试了以下方法,但失败了
allArrays = []
for x in range(0, 1000):
myArray = myFunction(x)
allArrays += myArray
错误是ValueError: operands could not be broadcast together with shapes (0) (9095)。我怎样才能让它工作?
例如这两个数组:
[ 234 342 234 5454 34 6]
[ 23 2 1 4 55 34]
应合并到这个数组中:
[ 234 342 234 5454 34 6 23 2 1 4 55 34 ]
【问题讨论】:
-
我想连接它们。
-
可能是 concatenate((a,b),1) 或 hstack((a,b)) 另见stackoverflow.com/questions/18404077/…