Reputation: 96378
I am running into errors when concatenating arrays in Python:
x = np.array([])
while condition:
% some processing
x = np.concatenate([x + new_x])
The error I get is:
----> 1 x = np.concatenate([x + new_x])
ValueError: operands could not be broadcast together with shapes (0) (6)
On a side note, is this an efficient way to grow a numpy
array in Python?
Upvotes: 2
Views: 7745
Reputation: 394
Alternatively:
x = np.append(x,new_x)
Regarding your side note, take a look here: How to extend an array in-place in Numpy?
Upvotes: 0