Complete the code to generate 5 random numbers from a normal distribution with mean 0 and standard deviation 1.
import numpy as np samples = np.random.normal(loc=0, scale=[1], size=5) print(samples)
The scale parameter sets the standard deviation. For a standard normal distribution, it is 1.
Complete the code to generate 10 random numbers from a normal distribution with mean 5 and standard deviation 2.
import numpy as np samples = np.random.normal(loc=[1], scale=2, size=10) print(samples)
The loc parameter sets the mean. Here, the mean is 5.
Fix the error in the code to generate 3 random numbers from a normal distribution with mean 0 and standard deviation 1.
import numpy as np samples = np.random.normal(loc=0, scale=1, size=[1]) print(samples)
The size parameter must be an integer, not a string. Use 3.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only include words longer than 4 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 4} print(lengths)
We want the length of each word as the value, so use len(word). To include words longer than 4 characters, use the condition len(word) > 4.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, including only words longer than 3 characters.
words = ['sun', 'moon', 'star', 'sky', 'planet'] result = { [1]: [2] for word in words if len(word) [3] 3 } print(result)
The keys should be uppercase words using word.upper(). The values are the lengths using len(word). The condition includes words longer than 3 characters using >.