Reputation: 219
I have the following code:
import numpy as np
x = np.zeros([4,N])
x[:,0]= np.vstack([1000,0,0,50])
However, I get the following error:
ValueError: could not broadcast input array from shape (4,1) into shape (4)
I'm quite confused as to why this isn't working, any help would be much appreciated.
Upvotes: 1
Views: 1336
Reputation: 358
This is due to the way slicing works in numpy as x[:,0]
in your case expects an array not a vector.
The correct way to achieve what you want is:
import np as numpy
x = np.zeros([4,N])
x[:,0]= np.array([1000,0,0,50])
Upvotes: 1