Complete the code to calculate the sum of all elements in the array.
import numpy as np arr = np.array([[1, 2], [3, 4]]) total_sum = arr.[1]()
The sum() function adds all elements in the array.
Complete the code to calculate the mean of the array elements along axis 0 (columns).
import numpy as np arr = np.array([[1, 2], [3, 4]]) col_mean = arr.[1](axis=0)
The mean(axis=0) calculates the average of each column.
Fix the error in the code to find the maximum value along axis 1 (rows).
import numpy as np arr = np.array([[5, 7, 2], [3, 8, 1]]) max_per_row = arr.[1](axis=1)
The max(axis=1) function finds the largest value in each row.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 characters.
words = ['cat', 'elephant', 'dog', 'giraffe'] lengths = {word: [1] for word in words if len(word) [2] 3}
We use len(word) to get the length and filter words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, but only for words longer than 4 characters.
words = ['apple', 'bat', 'carrot', 'dog'] result = { [1]: [2] for w in words if len(w) [3] 4 }
We convert words to uppercase for keys using w.upper(), get lengths with len(w), and filter words longer than 4 with >.