Overview
Turn a table of exam scores into a small report (class average, best student, pass count) with arrays, axes and masks together.
- mean(axis=1) per student
- argmax() and masks
- int() and float() for plain Python numbers
Short Course
Reports often end up as JSON. Trap: NumPy integers like np.int64 aren't
plain Python numbers, and json.dumps rejects them. Convert with int() or
float().
import json
best = np.array([4, 9]).argmax() # a NumPy integer
json.dumps({"best": best}) # TypeError!
json.dumps({"best": int(best)}) # '{"best": 1}'
Task
Each row of scores is one student. Write grade_report(scores) that returns
the class average rounded to 1 decimal, the index of the student with the best
average and how many students average 10 or more, for example
grade_report(np.array([[8, 10], [14, 16]])) gives
{'average': 12.0, 'best': 1, 'passed': 1}.
Test Suites
Pending
Next
Output