Complete the code to create a NumPy array and apply a ufunc to square each element.
import numpy as np arr = np.array([1, 2, 3, 4]) squared = np.[1](arr)
The np.square ufunc squares each element of the array efficiently.
Complete the code to apply a ufunc that adds 5 to each element of the array.
import numpy as np arr = np.array([10, 20, 30]) result = np.[1](arr, 5)
The np.add ufunc adds the second argument to each element of the array.
Fix the error in the code to correctly apply a ufunc that computes the natural logarithm of each element.
import numpy as np arr = np.array([1, 10, 100]) log_values = np.[1](arr)
The np.log ufunc computes the natural logarithm (base e) of each element.
Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
words = ['data', 'science', 'ai', 'ml'] lengths = {word: [1] for word in words if [2]
We 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 comprehension that maps each uppercase word to its length only if the length is greater than 2.
words = ['cat', 'dog', 'elephant'] result = { [1]: [2] for word in words if [3] }
The keys are uppercase words using word.upper(), values are lengths with len(word), and the condition filters words longer than 2 characters.