Complete the code to calculate the 50th percentile (median) of the data array.
import numpy as np data = np.array([10, 20, 30, 40, 50]) median = np.percentile(data, [1]) print(median)
The 50th percentile corresponds to the median, so we pass 50 to np.percentile().
Complete the code to calculate the 90th percentile of the data array.
import numpy as np data = np.array([5, 15, 25, 35, 45, 55]) ninetieth = np.percentile(data, [1]) print(ninetieth)
The 90th percentile means the value below which 90% of the data falls, so we pass 90 to np.percentile().
Complete the code to calculate the 25th percentile.
import numpy as np data = [1, 2, 3, 4, 5] percentile_25 = np.percentile([1], 25) print(percentile_25)
tolist() method, causing an AttributeError.np.percentile() accepts Python lists directly because they are array_like.
Fill both blanks to create a dictionary of percentiles for 25th and 75th percentiles.
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)
To get the 25th and 75th percentiles, pass 25 and 75 respectively to np.percentile().
Fill all three blanks to create a dictionary of percentiles for 10th, 50th, and 90th percentiles.
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)
Each percentile value matches the key: 10th, 50th, and 90th percentiles.