Complete the code to select all elements in the last dimension of a 3D NumPy array using ellipsis.
import numpy as np arr = np.arange(27).reshape(3, 3, 3) result = arr[1]
The ellipsis ... represents all preceding dimensions, so arr[..., :] selects all elements in the last dimension.
Complete the code to select the first element in the last dimension for all other dimensions using ellipsis.
import numpy as np arr = np.arange(24).reshape(2, 3, 4) result = arr[1]
arr[..., 0] selects the first element in the last dimension for all other dimensions.
Fix the error in the code to correctly select all elements in the last two dimensions using ellipsis.
import numpy as np arr = np.arange(60).reshape(3, 4, 5) result = arr[1]
The correct syntax to select all elements in the last two dimensions is arr[..., :, :].
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]
The dictionary comprehension maps each word to its length using len(word) and filters words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary comprehension that maps each word in uppercase to its length only if the length is greater than 2.
words = ['cat', 'dog', 'a', 'elephant'] result = [1]: [2] for word in words if [3]
The comprehension maps each word in uppercase (word.upper()) to its length (len(word)) only if the length is greater than 2 (len(word) > 2).