Aggregation Functions (sum, mean, std, etc.)
NumPy provides built-in functions that make it easy to summarize and analyze data in arrays.
With just one line of code, you can 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 summarize an entire array or operate along a specific axis for row-wise or column-wise results.
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