Reputation: 885
Here is a very straightforward version of the problem i am having reshaping a 40*1 array into a 20*2 array. What is going wrong here?
import numpy as np
x=np.linspace(1,20,40)
#confirm length is 40
print(np.shape(x))
#reshape to 2*20
print(np.reshape(x,2,20))
#returns error: 'total size of new array must be unchanged'
Upvotes: 3
Views: 111
Reputation: 33127
You do not use the function as you should use it.
Simply use this:
np.reshape(x,(2,20))
Full code:
import numpy as np
x=np.linspace(1,20,40)
#confirm length is 40
print(np.shape(x))
print(np.reshape(x,(2,20)))
Upvotes: 3