Skip to main content
Practice

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 values
  • np.mean(): average value
  • np.min(): smallest value
  • np.max(): largest value
  • np.std(): standard deviation
  • np.median(): middle value (helpful for distributions)

Axis Support

Aggregation functions can operate on the entire array or along a specific axis.

  • axis=0: column-wise
  • axis=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]

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.