Aggregation Functions (sum, mean, std, etc.)
NumPy provides built-in functions to summarize data stored in arrays.
These include operations like total, average, min, max, and standard deviation.
Common Aggregation Functions
np.sum()
– Total of all valuesnp.mean()
– Average valuenp.min()
/np.max()
– Smallest / largest valuenp.std()
– Standard deviationnp.median()
– Middle value (optional but useful)
Axis Support
These functions work on entire arrays or along a specific axis.
axis=0
: column-wiseaxis=1
: row-wise
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]
Summary
- Use aggregation functions to explore and summarize data
- Add
axis=0
oraxis=1
to control the direction of aggregation
What’s Next
You’ll now try using these functions in Jupyter to explore real arrays.