Complete the code to create a NumPy array from a Python list.
import numpy as np arr = np.[1]([1, 2, 3, 4]) print(arr)
The np.array function converts a Python list into a NumPy ndarray.
Complete the code to find the shape of the NumPy array.
import numpy as np arr = np.array([[1, 2], [3, 4], [5, 6]]) shape = arr.[1] print(shape)
The shape attribute shows the dimensions of the array as a tuple.
Fix the error in the code to correctly create a 2D NumPy array.
import numpy as np arr = np.array([1]) print(arr)
A 2D array requires a list of lists with equal lengths. Option C is correct.
Fill both blanks to create a 3x3 array of zeros and print its data type.
import numpy as np arr = np.[1]((3, 3), dtype=[2]) print(arr.dtype)
np.zeros creates an array of zeros. Setting dtype=float makes elements floats.
Fill all three blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.
words = ['data', 'science', 'ai', 'ml'] lengths = { [1]: [2] for word in words if [3] }
The dictionary comprehension uses the word as key, its length as value, and filters words longer than 3 characters.