Complete the code to generate 5 random numbers between 0 and 1 using NumPy.
import numpy as np random_numbers = np.random.[1](5) print(random_numbers)
The np.random.rand function generates random floats between 0 and 1. Here, it creates 5 such numbers.
Complete the code to generate 5 random integers between 1 and 10 (inclusive) using NumPy.
import numpy as np random_ints = np.random.[1](1, 11, 5) print(random_ints)
The np.random.randint function generates random integers. The arguments specify the start (inclusive), end (exclusive), and number of values.
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([1], 1, 3) print(samples)
The mean of the normal distribution should be 0 to get standard normal samples.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only include words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2] print(lengths)
We use len(word) to get the length and filter words with length greater than 3.
Fill both blanks to create a dictionary with uppercase words as keys and their lengths as values, including only words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word.upper(): {BLANK_2}} for word in words if {{BLANK_2}} print(lengths)
The dictionary starts with {. Keys are uppercase words using word.upper(), values are lengths, and filter checks length > 3.