Hello, Space Voyager! Today we're focusing on Array Shape and Reshape in NumPy
. Understanding an array's shape is like knowing the size of a box—it tells us how we can manipulate it. Meanwhile, reshaping an array is like changing a box's dimensions to meet our needs.
The shape of an array is its dimensions, which are the sizes along each of its axes. Thus, understanding an array's shape helps us comprehend its structure. The concept of reshaping allows us to adjust the array's dimensions.
NumPy
provides an easy way to find an array's shape with the shape
attribute. It's like getting the length of a list of toys in a box, which is the total number of toys, or the size of our array.
With a 2D array, the shape
attribute returns a pair of numbers: the number of rows and columns.
With NumPy
's method, we can flexibly change an array's shape without altering its data.
