Complete the code to create a 2D array of shape (3, 3) filled with ones.
import numpy as np array = np.[1]((3, 3))
The np.ones function creates an array filled with ones.
Complete the code to add a 1D array to each row of a 2D array using broadcasting.
import numpy as np arr2d = np.array([[1, 2, 3], [4, 5, 6]]) arr1d = np.array([10, 20, 30]) result = arr2d + [1]
Adding arr1d directly works because its shape (3,) broadcasts correctly across the columns of arr2d.
Fix the error in the code that tries to add arrays with incompatible shapes.
import numpy as np arr1 = np.array([[1, 2, 3], [4, 5, 6]]) arr2 = np.array([10, 20, 30]) result = arr1 + [1]
Adding arr2 directly works because its shape (3,) broadcasts correctly across the columns of arr1.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['data', 'ai', 'science', 'ml'] lengths = {word: [1] for word in words if [2]
Use len(word) to get length and filter with len(word) > 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 3.
words = ['data', 'ai', 'science', 'ml'] result = { [1]: [2] for word in words if [3] }
Map uppercase words (word.upper()) to their lengths (len(word)) only if length is greater than 3 (len(word) > 3).