Skip to main content
Practice

Array Shapes, Axes, and Broadcasting

To understand how NumPy arrays work in operations, you need to know about shapes and axes.


Shape

Every array has a .shape, which shows how many elements it has in each dimension.

For example, an array with 2 rows and 3 columns has a shape of (2, 3).


Axes

An axis is a direction along which an operation is applied.

  • axis=0: down the rows (vertical)
  • axis=1: across the columns (horizontal)

You will use axes with functions like sum(), mean(), and others.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.