Complete the code to create a NumPy array from a Python list.
import numpy as np arr = np.[1]([1, 2, 3, 4, 5])
The np.array function converts a Python list into a NumPy array, which allows vectorized operations.
Complete the code to add 5 to every element in the NumPy array using vectorized operations.
import numpy as np arr = np.array([1, 2, 3]) result = arr [1] 5
Using the + operator adds 5 to each element of the array in a vectorized way.
Fix the error in the code to multiply two NumPy arrays element-wise.
import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5, 6]) result = arr1 [1] arr2
The * operator performs element-wise multiplication between two NumPy arrays.
Fill both blanks to create a vectorized operation that squares each element and then filters elements greater than 10.
import numpy as np arr = np.array([1, 2, 3, 4]) squared = arr [1] 2 filtered = squared[squared [2] 10]
Use ** to square elements and > to filter elements greater than 10.
Fill all three blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
words = ['data', 'is', 'fun', 'and', 'cool'] lengths = { [1] : [2] for [3] in words if len([3]) > 3 }
The comprehension uses word as the key, len(word) as the value, and iterates over word in words.