0
0
NumPydata~15 mins

np.searchsorted() for insertion points in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Find Insertion Points Using np.searchsorted()
📖 Scenario: Imagine you have a sorted list of exam scores. You want to find where new students' scores would fit in this list to keep it sorted.
🎯 Goal: You will learn how to use np.searchsorted() to find the correct positions to insert new scores into a sorted array.
📋 What You'll Learn
Create a sorted numpy array called sorted_scores with exact values
Create a numpy array called new_scores with exact values
Use np.searchsorted() with sorted_scores and new_scores to find insertion points
Print the resulting insertion points array
💡 Why This Matters
🌍 Real World
Finding insertion points is useful in ranking systems, scheduling, or any case where you keep data sorted and want to add new entries correctly.
💼 Career
Data scientists often need to insert new data points into sorted datasets efficiently, and <code>np.searchsorted()</code> helps with this task.
Progress0 / 4 steps
1
Create the sorted scores array
Create a numpy array called sorted_scores with these exact values: [55, 65, 75, 85, 95].
NumPy
Need a hint?

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

2
Create the new scores array
Create a numpy array called new_scores with these exact values: [60, 80, 90].
NumPy
Need a hint?

Use np.array() again to create the new scores array.

3
Find insertion points using np.searchsorted()
Use np.searchsorted() with sorted_scores and new_scores to find the insertion points. Store the result in a variable called insertion_points.
NumPy
Need a hint?

Call np.searchsorted() with the sorted array first, then the values to insert.

4
Print the insertion points
Print the variable insertion_points to display the positions where new scores fit in the sorted array.
NumPy
Need a hint?

Use print(insertion_points) to show the result.