Complete the code to create a NumPy array of zeros with shape (3, 4).
import numpy as np arr = np.[1]((3, 4))
The np.zeros function creates an array filled with zeros of the specified shape.
Complete the code to add a 1D array to each row of a 2D array using broadcasting.
import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]]) add = np.array([10, 20, 30]) result = arr + [1]
Reshaping add to (1, 3) allows it to broadcast correctly across each row of arr.
Fix the error in the code to multiply a 2D array by a 1D array along columns using broadcasting.
import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]]) multiplier = np.array([2, 3]) result = arr * [1]
Reshaping multiplier to (2, 1) aligns it with the rows of arr for correct broadcasting.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2]
The dictionary maps each word to its length, but only includes words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 4.
words = ['apple', 'bat', 'carrot', 'dog'] result = {{ [1]: [2] for w in words if [3] }}
The dictionary comprehension converts each word to uppercase as the key, maps it to its length, and includes only words longer than 4 characters.