Complete the code to import the SciPy stats module.
from scipy import [1] print(stats.norm.cdf(0))
The stats module in SciPy provides statistical functions like the normal cumulative distribution function (cdf).
Complete the code to create a NumPy array of 5 random numbers from a normal distribution using SciPy.
import numpy as np from scipy import stats random_nums = stats.norm.[1](size=5) print(random_nums)
cdf or pdf which compute probabilities, not samples.ppf which is the percent point function (inverse cdf).The rvs function generates random variates (random samples) from the specified distribution.
Fix the error in the code to calculate the mean of a NumPy array.
import numpy as np arr = np.array([1, 2, 3, 4, 5]) mean_value = arr.[1]() print(mean_value)
average() which is a NumPy function but not an array method.The correct method to calculate the mean of a NumPy array is mean().
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['data', 'science', 'is', 'fun'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) to get the length and filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 2 characters.
words = ['apple', 'to', 'banana', 'go'] result = { [1]: [2] for w in words if len(w) [3] 2 } print(result)
The dictionary comprehension uses w.upper() as keys, len(w) as values, and filters words with length greater than 2 using >.