Complete the code to select the first row of the array using basic indexing.
import numpy as np arr = np.array([[1, 2], [3, 4], [5, 6]]) first_row = arr[1]
Using [0] selects the first row as a 1D array.
Complete the code to select rows 0 and 2 using advanced indexing.
import numpy as np arr = np.array([[1, 2], [3, 4], [5, 6]]) selected_rows = arr[[1]]
Advanced indexing requires a list or array inside the brackets. Using [0, 2] correctly selects rows 0 and 2.
Fix the error in the code to select elements at positions (0,1) and (2,0) using advanced indexing.
import numpy as np arr = np.array([[1, 2], [3, 4], [5, 6]]) result = arr[[1], [2]]
To select elements at (0,1) and (2,0), you need two arrays of indices: one for rows and one for columns. Using np.array([0, 2]) for rows and np.array([1, 0]) for columns fixes the error.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['data', 'science', 'is', 'fun'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension maps each word to its length using len(word). The condition len(word) > 3 filters words longer than 3 characters.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 2.
words = ['AI', 'ML', 'Data', 'Code'] result = [1]: [2] for w in words if [3]
The dictionary comprehension maps each word in uppercase (w.upper()) to its length (len(w)) only if the length is greater than 2 (len(w) > 2).