Editor

Rank the Top 3 Scores

Intermediate · Write the code · from NumPy Operations: Element-wise Math, Aggregations, and ufuncs

From the lesson: NumPy Operations: Element-wise Math, Aggregations, and ufuncs

You know how to create NumPy arrays. Now it's time to actually do things with them. The real power of NumPy is that you can perform math on entire arrays at once - no loops required.

Read the lesson

Given names = np.array(['Alice', 'Bob', 'Charlie', 'Diana', 'Eve']) and scores = np.array([82, 95, 78, 91, 88]), use np.argsort() and fancy indexing to print the names of the top 3 scorers in descending order of score.

import numpy as np
names = np.array(['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'])
scores = np.array([82, 95, 78, 91, 88])
# Print top 3 names in descending score order

More NumPy Operations exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz