Complete the code to add a scalar value 5 to each element of the array.
import numpy as np arr = np.array([1, 2, 3]) result = arr [1] 5 print(result)
The plus sign + adds the scalar 5 to each element of the array using broadcasting.
Complete the code to multiply each element of the array by 10 using broadcasting.
import numpy as np arr = np.array([4, 5, 6]) result = arr [1] 10 print(result)
The multiplication operator * multiplies each element by 10 using broadcasting.
Fix the error in the code to subtract 3 from each element of the array using broadcasting.
import numpy as np arr = np.array([7, 8, 9]) result = arr [1] 3 print(result)
The subtraction operator - subtracts 3 from each element using broadcasting.
Fill both blanks to create a new array where each element is the original element divided by 2 and then added to 4.
import numpy as np arr = np.array([2, 4, 6]) result = (arr [1] 2) [2] 4 print(result)
First, divide each element by 2 using /, then add 4 using + with broadcasting.
Fill all three blanks to create a dictionary where keys are the original array elements squared, values are the elements multiplied by 3, but only include elements greater than 2.
import numpy as np arr = np.array([1, 2, 3, 4]) result = { [1]: [2] for x in arr if x [3] 2 } print(result)
The dictionary comprehension uses x**2 as keys, x*3 as values, and includes only elements where x > 2.