Challenge - 5 Problems
Sorting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of sorting a NumPy array
What is the output of this code that sorts a NumPy array?
NumPy
import numpy as np arr = np.array([3, 1, 4, 1, 5]) sorted_arr = np.sort(arr) print(sorted_arr)
Attempts:
2 left
💡 Hint
Think about what sorting does to the order of elements.
✗ Incorrect
np.sort returns a new array with elements in ascending order. The original array stays the same.
❓ data_output
intermediate2:00remaining
Number of elements after sorting with unique
What is the number of unique elements after sorting this NumPy array?
NumPy
import numpy as np arr = np.array([2, 3, 2, 5, 3, 7]) unique_sorted = np.unique(arr) print(len(unique_sorted))
Attempts:
2 left
💡 Hint
Unique elements are counted after sorting and removing duplicates.
✗ Incorrect
np.unique returns sorted unique elements. The array has 4 unique values: 2, 3, 5, 7.
🔧 Debug
advanced2:00remaining
Identify the error in sorting a 2D array
What error does this code raise when trying to sort a 2D NumPy array incorrectly?
NumPy
import numpy as np arr = np.array([[3, 2], [1, 4]]) sorted_arr = np.sort(arr, axis=2) print(sorted_arr)
Attempts:
2 left
💡 Hint
Check the dimensions of the array and the axis parameter.
✗ Incorrect
The array has 2 dimensions (axes 0 and 1). Axis 2 does not exist, causing IndexError.
🚀 Application
advanced2:00remaining
Sorting to find median in NumPy
Which code correctly finds the median of a NumPy array by sorting?
Attempts:
2 left
💡 Hint
Median is the middle value after sorting.
✗ Incorrect
Option D sorts the array and picks the middle element correctly. Option D uses np.median but does not show sorting. Option D is similar but misses storing sorted array. Option D calculates mean, not median.
🧠 Conceptual
expert2:00remaining
Why sorting is important in data science
Why is sorting data important before applying many data science algorithms?
Attempts:
2 left
💡 Hint
Think about how sorted data helps algorithms work faster or better.
✗ Incorrect
Sorting arranges data in order, which helps algorithms like binary search, grouping, and visualization work efficiently. It does not change values, remove duplicates, or encrypt data.