Challenge - 5 Problems
Percentile Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of np.percentile() on a simple array
What is the output of this code snippet?
NumPy
import numpy as np arr = np.array([10, 20, 30, 40, 50]) result = np.percentile(arr, 40) print(result)
Attempts:
2 left
💡 Hint
Percentile 40 means the value below which 40% of data falls.
✗ Incorrect
The 40th percentile is calculated by linear interpolation between 20 and 30, resulting in 26.0.
❓ data_output
intermediate2:00remaining
Percentiles of a 2D array along axis 0
What is the output of np.percentile(arr, 50, axis=0) for the given 2D array?
NumPy
import numpy as np arr = np.array([[1, 3, 5], [2, 4, 6], [3, 5, 7]]) result = np.percentile(arr, 50, axis=0) print(result)
Attempts:
2 left
💡 Hint
50th percentile is the median along the specified axis.
✗ Incorrect
The median along axis 0 is the middle value of each column: [2, 4, 6].
❓ visualization
advanced3:00remaining
Visualizing percentiles on a dataset
Which option correctly describes the plot generated by this code?
NumPy
import numpy as np import matplotlib.pyplot as plt np.random.seed(0) data = np.random.normal(0, 1, 1000) percentiles = np.percentile(data, [25, 50, 75]) plt.hist(data, bins=30, alpha=0.5) for p in percentiles: plt.axvline(p, color='r', linestyle='--') plt.show()
Attempts:
2 left
💡 Hint
Percentiles 25, 50, and 75 correspond to quartiles.
✗ Incorrect
The code plots a histogram and draws vertical red dashed lines at the 25th, 50th (median), and 75th percentiles.
🧠 Conceptual
advanced2:00remaining
Understanding interpolation in np.percentile()
If np.percentile() is called with interpolation='nearest' on the array [1, 2, 3, 4], what is the 30th percentile value?
NumPy
import numpy as np arr = np.array([1, 2, 3, 4]) result = np.percentile(arr, 30, interpolation='nearest') print(result)
Attempts:
2 left
💡 Hint
Nearest interpolation picks the closest data point to the percentile rank.
✗ Incorrect
The 30th percentile rank corresponds closest to the second element (value 2) when using nearest interpolation.
🔧 Debug
expert2:00remaining
Error raised by incorrect np.percentile() usage
What error does this code raise?
NumPy
import numpy as np arr = np.array([1, 2, 3]) result = np.percentile(arr, 110) print(result)
Attempts:
2 left
💡 Hint
Percentiles must be between 0 and 100 inclusive.
✗ Incorrect
Percentile values outside 0-100 range cause a ValueError in np.percentile().