3

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'
3
  • let me know if my answer helps Commented Nov 22, 2018 at 22:58
  • You haven't read the docs closely enough Commented Nov 22, 2018 at 22:58
  • @seralouk yes, it answers my question exactly. thanks! Commented Nov 22, 2018 at 23:00

1 Answer 1

3

You do not use the function as you should use it.

Simply use this:

np.reshape(x,(2,20))

Documentation here

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)))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.