Complete the code to create a NumPy array from a Python list.
import numpy as np numbers = [1, 2, 3, 4, 5] array = np.[1](numbers) print(array)
The np.array() function converts a Python list into a NumPy array, which allows fast numerical operations.
Complete the code to add 5 to every element in the NumPy array.
import numpy as np arr = np.array([10, 20, 30]) result = arr [1] 5 print(result)
Adding 5 to a NumPy array adds 5 to each element because NumPy supports element-wise operations.
Fix the error in the code to compute the mean of the array elements.
import numpy as np arr = np.array([2, 4, 6, 8]) mean_value = arr.[1]() print(mean_value)
The correct NumPy method to compute the average value is mean().
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 letters.
words = ['cat', 'elephant', 'dog', 'giraffe'] lengths = {word: [1] for word in words if [2] print(lengths)
Use len(word) to get the length and filter words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 4 letters.
words = ['apple', 'bat', 'carrot', 'dog'] result = { [1]: [2] for w in words if [3] } print(result)
The keys are uppercase words using w.upper(), values are lengths with len(w), and filter words longer than 4 with len(w) > 4.