Aggregation Functions (sum, mean, std, etc.)
NumPy includes built-in functions to quickly summarize data stored in arrays.
These let you calculate totals, averages, minimums, maximums, and more.
Common Aggregation Functions
np.sum()
: total of all valuesnp.mean()
: average valuenp.min()
: smallest valuenp.max()
: largest valuenp.std()
: standard deviationnp.median()
: middle value (helpful for distributions)
Axis Support
Aggregation functions can operate on the entire array or along a specific axis.
axis=0
: column-wiseaxis=1
: row-wise
Aggregation Functions
arr = np.array([[1, 2], [3, 4]]) print(arr.sum()) # Sum of all elements print(arr.sum(axis=0)) # Sum down columns → [4 6] print(arr.sum(axis=1)) # Sum across rows → [3 7]
Quiz
0 / 1
Which NumPy aggregation function calculates the average value of an array?
np.sum()
np.min()
np.mean()
np.std()
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help