0
0
NumPydata~15 mins

np.argsort() for sort indices in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Using np.argsort() to Sort Indices in NumPy
📖 Scenario: You have a list of exam scores from students. You want to find out the order of students from the lowest score to the highest score without changing the original list.
🎯 Goal: Build a program that uses np.argsort() to find the indices that would sort the scores array.
📋 What You'll Learn
Create a NumPy array called scores with exact values
Create a variable called sorted_indices using np.argsort() on scores
Print the sorted_indices to show the order of scores from lowest to highest
💡 Why This Matters
🌍 Real World
Sorting indices is useful when you want to know the order of items without changing the original data, such as ranking students by scores or sorting products by price.
💼 Career
Data scientists often use <code>np.argsort()</code> to efficiently sort data and keep track of original positions, which is important for data analysis and machine learning tasks.
Progress0 / 4 steps
1
Create the scores array
Create a NumPy array called scores with these exact values: 55, 89, 76, 65, 92.
NumPy
Need a hint?

Use np.array() to create the array with the exact values.

2
Use np.argsort() to get sorted indices
Create a variable called sorted_indices and set it to np.argsort(scores).
NumPy
Need a hint?

Use np.argsort() to get the indices that would sort the array.

3
Print the sorted indices
Write a print() statement to display the sorted_indices variable.
NumPy
Need a hint?

The output should be the indices that sort the scores from lowest to highest.

4
Use sorted indices to sort the scores
Create a variable called sorted_scores by using scores[sorted_indices]. Then print sorted_scores.
NumPy
Need a hint?

Use the sorted indices to reorder the original scores array and print the sorted scores.