Back to NUMPY FOUNDATIONS

NumPy Aggregations

Learn aggregation operations like sum, mean, min, max, and how to apply them along different axes.

4 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. Aggregate Function Definition — Aggregate functions summarize data and typically return a single value.
  2. Setup and Basic Sum — A 2D array is created, and the `np.sum()` function is demonstrated to calculate the total of all elements.
  3. Mean, STD, and Variance — The functions `np.mean()`, `np.std()`, and `np.var()` are introduced for calculating statistical measures.
  4. Min, Max, and Position — Functions `np.min()`, `np.max()`, `np.argmin()`, and `np.argmax()` are used to find extreme values and their indices.
  5. Axis Aggregation (Columns) — The `axis=0` parameter is used with `np.sum()` to aggregate the data column-wise.
  6. Axis Aggregation (Rows) — The `axis=1` parameter is used with `np.sum()` to aggregate the data row-wise.
PDF notes

Frequently asked questions

What is the difference between variance and standard deviation?

Standard deviation (`np.std`) is the measure of spread in the original units of the data. Variance (`np.var`) is the square of the standard deviation.

Why does `np.argmin()` return a single index for a 2D array?

By default, NumPy aggregates treat the multi-dimensional array as flattened (row-major order) unless an axis is specified.

What happens if I don't specify the `axis` parameter?

The function operates on the entire array, treating all elements as a single sequence and returning one scalar value.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.