Average precision scores one ranking. An object detector produces one ranking per class — all its "dog" boxes ranked by confidence, all its "car" boxes, and so on — and you need a single number for the whole detector.
mAP is the plainest possible answer: compute average precision for each class separately, then take the mean of those scores.
Task: write mean_average_precision(y_true_per_class, scores_per_class) returning that mean, rounded to 4 decimal places.
y_true_per_class[2] and scores_per_class[2] describe the same class.That last rule is the one worth remembering. A class with three examples counts as much as a class with three thousand, so a detector that nails the common classes and ignores a rare one cannot hide behind its own data volume.