Complete the code to calculate the mean of the sample data.
import numpy as np sample = [5, 7, 8, 6, 9] mean_value = np.[1](sample) print(mean_value)
The mean function calculates the average value of the sample data, which is essential for hypothesis testing.
Complete the code to calculate the standard deviation of the sample.
import numpy as np sample = [5, 7, 8, 6, 9] std_dev = np.[1](sample, ddof=1) print(std_dev)
The std function calculates the standard deviation, which measures how spread out the data is. The parameter ddof=1 gives the sample standard deviation.
Fix the error in the code to calculate the t-statistic for hypothesis testing.
import numpy as np sample = [5, 7, 8, 6, 9] mean_sample = np.mean(sample) std_sample = np.std(sample, ddof=1) n = len(sample) t_stat = (mean_sample - 6) / (std_sample / [1]) print(t_stat)
The denominator of the t-statistic uses the standard error, which is the standard deviation divided by the square root of the sample size.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['data', 'is', 'fun', 'and', 'useful'] lengths = {word: [1] for word in words if [2] > 3} print(lengths)
The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a filtered dictionary of uppercase keys and values greater than 0.
data = {'a': 1, 'b': -2, 'c': 3}
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
print(result)The dictionary comprehension creates keys as uppercase letters using k.upper(), keeps values as v, and filters only values greater than zero with v > 0.