0
0
NumPydata~10 mins

Percentiles with np.percentile() in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the 50th percentile (median) of the data array.

NumPy
import numpy as np

data = np.array([10, 20, 30, 40, 50])
median = np.percentile(data, [1])
print(median)
Drag options to blanks, or click blank then click option'
A25
B75
C50th
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using the value 50th as a string instead of the number 50.
Passing the wrong percentile number like 25 or 75.
2fill in blank
medium

Complete the code to calculate the 90th percentile of the data array.

NumPy
import numpy as np

data = np.array([5, 15, 25, 35, 45, 55])
ninetieth = np.percentile(data, [1])
print(ninetieth)
Drag options to blanks, or click blank then click option'
A90
B75
C85
D95
Attempts:
3 left
💡 Hint
Common Mistakes
Using 75 or 85 instead of 90.
Passing the percentile as a string like '90' instead of number 90.
3fill in blank
hard

Complete the code to calculate the 25th percentile.

NumPy
import numpy as np

data = [1, 2, 3, 4, 5]
percentile_25 = np.percentile([1], 25)
print(percentile_25)
Drag options to blanks, or click blank then click option'
Adata
Bnp.array(data)
Clist(data)
Ddata.tolist()
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting D: lists do not have a tolist() method, causing an AttributeError.
Unnecessarily converting when not needed (though B and C also work).
4fill in blank
hard

Fill both blanks to create a dictionary of percentiles for 25th and 75th percentiles.

NumPy
import numpy as np

data = np.array([2, 4, 6, 8, 10])
percentiles = {25: np.percentile(data, [1]), 75: np.percentile(data, [2])}
print(percentiles)
Drag options to blanks, or click blank then click option'
A25
B50
C75
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using 50 or 100 instead of 25 or 75.
Mixing up the percentile values for the keys.
5fill in blank
hard

Fill all three blanks to create a dictionary of percentiles for 10th, 50th, and 90th percentiles.

NumPy
import numpy as np

data = np.array([3, 6, 9, 12, 15])
percentiles = {10: np.percentile(data, [1]), 50: np.percentile(data, [2]), 90: np.percentile(data, [3])}
print(percentiles)
Drag options to blanks, or click blank then click option'
A10
B50
C90
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using 100 instead of 90 for the last percentile.
Mixing up the percentile numbers.