NumPy Statistics

sum, mean, median, std and more.

✍️ 3 exercises + code challenge in this lesson
  • arr.sum(), arr.mean(), np.median(arr), arr.std()
  • arr.min(), arr.max(), arr.argmax() (index of the max)
  • On 2-D arrays, axis=0 works down columns and axis=1 across rows.

Key Takeaways: NumPy Statistics

Mastering NumPy Statistics helps you write clean and reliable NumPy code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

NumPy Statistics Code Example

NumPy
import numpy as np

sales = np.array([[120, 150, 90], [200, 180, 220]])
print(sales.sum())
print(sales.sum(axis=0))
print(sales.mean(axis=1))
print(np.median([3, 1, 4, 1, 5]))
print(sales.argmax())
Output
960
[320 330 310]
[120. 200.]
3.0
5
Free sign-in required · Google login available

NumPy Statistics Practice Exercises

Check what you learned in “NumPy Statistics”.

/ 3 solved
Fill in the blank

Sum each column of a 2-D array.

m.sum(axis=)
✓ Correct! Not quite. Try again.
Multiple choice

Which function returns the index of the largest value?

✓ Correct! Not quite. Try again.
Code challenge

Print the mean of the marks.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services