Complete the code to select elements from a 2D array using fancy indexing.
import numpy as np arr = np.array([[10, 20, 30], [40, 50, 60], [70, 80, 90]]) result = arr[[1], [0, 2]]
The code uses fancy indexing to select rows 1 and 2 and columns 0 and 2, resulting in elements 40, 60, 70, and 90.
Complete the code to select elements from a 3x3 array using fancy indexing with two arrays.
import numpy as np arr = np.arange(9).reshape(3, 3) result = arr[[1], [0, 2, 1]]
Using row indices [0, 1, 2] and column indices [0, 2, 1] selects elements (0,0), (1,2), and (2,1) from the array.
Fix the error in the code to correctly select elements using multi-dimensional fancy indexing.
import numpy as np arr = np.array([[1, 2], [3, 4], [5, 6]]) result = arr[[0, 2], [1]]
The code selects elements at positions (0,1) and (2,1), which are 2 and 6 respectively.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['data', 'science', 'ai', 'ml'] lengths = { [1] : len([2]) for word in words if len(word) > 3 }
The dictionary comprehension uses each word as the key and its length as the value, filtering words longer than 3 characters.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 3.
words = ['data', 'science', 'ai', 'ml'] lengths = { [1] : [2] for word in words if len(word) [3] 3 }
The comprehension maps each word in uppercase to its length, filtering words longer than 3 characters.