Reshape
reshape changes the shape without changing the data. Use -1 to let NumPy compute one dimension.
Example
import numpy as np
a = np.arange(6)
print(a.reshape(2, 3))
print(a.reshape(3, -1))
print(a.reshape(2, 3).ravel())Result
[[0 1 2] [3 4 5]] [[0 1] [2 3] [4 5]] [0 1 2 3 4 5]
Exercise
Let NumPy pick a dimension.
a.reshape(2, )
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.