Complete the code to square each element in the array using np.square().
import numpy as np arr = np.array([1, 2, 3, 4]) squared = np.[1](arr) print(squared)
np.square() computes the square of each element in the array.
Complete the code to raise each element in the array to the power of 3 using np.power().
import numpy as np arr = np.array([1, 2, 3, 4]) cubed = np.power(arr, [1]) print(cubed)
np.power(arr, 3) raises each element of arr to the power of 3 (cube).
Fix the error in the code to correctly square the array elements using np.power().
import numpy as np arr = np.array([2, 3, 4]) squared = np.power(arr, [1]) print(squared)
The second argument to np.power() is the exponent. To square, use 2.
Fill both blanks to create a dictionary with words as keys and their squared lengths as values, only for words longer than 3 characters.
import numpy as np words = ['data', 'science', 'ai', 'ml'] squared_lengths = {word: [1] for word in words if len(word) [2] 3} print(squared_lengths)
We square the length using np.square(len(word)) and filter words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase words as keys and their squared lengths as values, only for words longer than 2 characters.
import numpy as np words = ['cat', 'dog', 'a', 'elephant'] squared_lengths = { [1]: [2] for word in words if len(word) [3] 2} print(squared_lengths)
Keys are uppercase words using word.upper(), values are squared lengths using np.square(len(word)), and filter words longer than 2 using >.