NumPy TutorialLesson 9Free preview
NumPy Array Shape
This lesson is part of NumPy · All levels
Summary
Shape is a tuple that describes the number of elements in each dimension of an array. You can read the shape through the .shape attribute, calculate dimensions with .ndim, number of elements with .size, and memory size with .nbytes. Understanding the shape is important because many of the errors in array operation come from the wrong shape.
Key points
- Returns the tuple of each dimension, for example (3, 4).
- .ndim shows the number of dimensions of the array.
- .size is the total number of elements, whereas .nbytes is the total byte.
- Reshape changes the shape of the array without changing the data in it.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.