Data Science · Level 1 Statistics

NumPy Sum, Mean & Max

Summarize a week of sales with one call each, and find which day was the best with argmax().

  • sum(), mean(), max()
  • argmax() gives a position
  • Positions start at 0

Arrays have built-in summaries: sum(), mean(), max(), min(). argmax() tells you where the maximum is, not its value. Trap: positions start at 0.

visits = np.array([120, 340, 90])
visits.mean()     # 183.33...
visits.max()      # 340
visits.argmax()   # 1: the second day

Write best_day(sales, days) that returns the name of the day with the highest sales, for example best_day([5, 9, 2], ["Mon", "Tue", "Wed"]) gives "Tue".

solution.py
Test Suites Pending
Output