2

在 Python 中连接数组时遇到错误:

x = np.array([])
while condition:
    % some processing 
    x = np.concatenate([x + new_x])

我得到的错误是:

----> 1 x = np.concatenate([x + new_x])

ValueError: operands could not be broadcast together with shapes (0) (6) 

附带说明一下,这是在 Python 中增长numpy数组的有效方法吗?

4

2 回答 2

3

看起来你想打电话

x = np.concatenate((x, new_x))

根据文档

于 2012-12-05T17:52:21.210 回答
0

或者:

x = np.append(x,new_x)

关于您的旁注,请看这里:如何在 Numpy 中就地扩展数组?

于 2012-12-05T18:56:20.000 回答