Understanding Shape and Reshape

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.

Understanding Shapes

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.

Investigating Array Shape

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.

Reshaping Array

With NumPy's method, we can flexibly change an array's shape without altering its data.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal