Skip to main content
Practice

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 values
  • np.mean() – Average value
  • np.min() / np.max() – Smallest / largest value
  • np.std() – Standard deviation
  • np.median() – Middle value (optional but useful)

Axis Support

These functions work on entire arrays or along a specific axis.

  • axis=0: column-wise
  • axis=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 or axis=1 to control the direction of aggregation

What’s Next

You’ll now try using these functions in Jupyter to explore real arrays.