NumPy TutorialLesson 10Free preview
NumPy Array Reshape
This lesson is part of NumPy · All levels
Summary
Reshape changes the shape of the array without changing the number or sequence of the data, as long as the total of the elements remains the same. Parameter -1 asks NumPy to calculate the remaining dimensions automatically. The ravel and flatten functions restore the one-dimensional version, with the ravel potentially producing a view and flatten that is always a copy.
Key points
- Reshape(n, m) changes shape as long as the number of elements remains appropriate.
- The -1 on one dimension makes NumPy automatically calculate it.
- Returns 1D arrays in view if possible.
- Always return a safe and modified 1D copy.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.