Complete the code to select rows 1 and 3, and columns 2 to 4 from the array.
import numpy as np arr = np.arange(20).reshape(5,4) result = arr[[1], 2:4] print(result)
Using fancy indexing with [1, 3] selects rows 1 and 3. The slice 2:4 selects columns 2 to 3.
Complete the code to select rows 0, 2, 4 and columns 1 and 3 from the array.
import numpy as np arr = np.arange(20).reshape(5,4) result = arr[[1], [1, 3]] print(result)
Fancy indexing with [0, 2, 4] selects rows 0, 2, and 4. Columns 1 and 3 are selected by the list [1, 3].
Fix the error in the code to select rows 1 and 2, and columns 0 to 2.
import numpy as np arr = np.arange(15).reshape(3,5) result = arr[[1], 0:3] print(result)
Fancy indexing requires a list or array of indices. Using [1, 2] correctly selects rows 1 and 2.
Fill both blanks to create a dictionary with words as keys and their lengths if length > 3.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) as the value and filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.
data = {'a': 1, 'b': -2, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0}
print(result)The dictionary comprehension uses uppercase keys with k.upper(), values v, and filters values greater than 0 using >.