Complete the code to create a NumPy array from a Python list.
import numpy as np arr = np.[1]([1, 2, 3, 4])
The np.array function converts a Python list into a NumPy array.
Complete the code to find the shape of a NumPy array.
import numpy as np arr = np.array([[1, 2], [3, 4], [5, 6]]) shape = arr.[1]
size which returns total elements, not shapelen() which only returns the first dimensionThe shape attribute returns the dimensions of the array as a tuple.
Fix the error in the code to correctly create a 2D NumPy array filled with zeros.
import numpy as np arr = np.zeros([1])
The np.zeros function requires a tuple to specify the shape of the array.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['apple', 'bat', 'cat', 'doggy'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 2.
words = ['hi', 'hello', 'hey'] result = { [1]: [2] for word in words if [3] }
word.lower() instead of uppercaseThe comprehension maps the uppercase version of each word to its length, filtering words longer than 2 characters.