NumPy II

Array Aggregation

Learn how to summarize NumPy arrays using aggregation functions like np.sum(), np.mean(), np.min(), and np.max(), and how to aggregate along specific axes of 2D arrays.


NumPy provides built-in functions to summarize array data — computing totals, averages, extremes, and spread in one call.

Use np.sum() and np.mean() to compute the total and average:

Python
Output

What will be the output?

Python

np.min() and np.max() return the smallest and largest values:

Python
Output

What will be the output?

Python

On 2D arrays, the axis parameter controls direction: axis=0 aggregates down columns, axis=1 aggregates across rows.

Sum along columns (axis=0) and along rows (axis=1):

Python
Output

What will be the output?

Python

np.argmin() and np.argmax() return the index of the smallest or largest value:

Python
Output

What will be the output?

Python

What will be the output?

Python