Skip to course content
Free course

Python Foundations / Module 8 / Aggregation and Axes

Module 8 lesson

Aggregation and Axes

Unit ID: M08-U05 Estimated active time: 25-35 minutes

The axis tells NumPy which dimension to collapse.

learner_totals = study_minutes.sum(axis=1)
weekly_means = study_minutes.mean(axis=0)
overall_mean = study_minutes.mean()

If rows are learners and columns are weeks:

  • axis=1 collapses columns and returns one result per learner;
  • axis=0 collapses rows and returns one result per week; and
  • no axis returns one result for the full array.

Do not memorise axis numbers without naming the result shape. Predict that shape first.

Practice: calculate weekly maximums, learner minimums, and the overall median. Write the expected shape before running each expression.