Complete the code to select elements at positions 1, 3, and 4 from the array.
import numpy as np arr = np.array([10, 20, 30, 40, 50]) selected = arr[[1]] print(selected)
The code uses fancy indexing with the integer array [1, 3, 4] to select elements at these positions.
Complete the code to select elements at indices stored in the variable 'indices'.
import numpy as np arr = np.array([5, 10, 15, 20, 25]) indices = np.array([0, 2, 4]) result = arr[[1]] print(result)
Fancy indexing works directly with a numpy array of indices, so 'arr[indices]' selects the elements at those positions.
Fix the error in the code to correctly select elements at indices 2, 0, and 3.
import numpy as np arr = np.array([7, 14, 21, 28, 35]) indices = [2, 0, 3] selected = arr[[1]] print(selected)
Fancy indexing works with a list of integers as well, so using 'indices' directly is correct.
Fill both blanks to create a new array selecting elements at indices 1 and 4, then multiply them by 10.
import numpy as np arr = np.array([3, 6, 9, 12, 15]) selected = arr[[1]] result = selected [2] 10 print(result)
The code selects elements at indices 1 and 4, then multiplies them by 10 using the '*' operator.
Fill all three blanks to create a dictionary mapping selected elements to their squares for indices 0, 2, and 3.
import numpy as np arr = np.array([2, 4, 6, 8, 10]) squares = { [1]: [2]**2 for [3] in arr[ [0, 2, 3] ] } print(squares)
The dictionary comprehension uses 'x' as the variable to map each selected element to its square.