Complete the code to create a view of the first three elements of the array.
import numpy as np arr = np.array([1, 2, 3, 4, 5]) view = arr[1]
The slice [0:3] creates a view of the first three elements of the array.
Complete the code to modify the view and show it affects the original array.
import numpy as np arr = np.array([10, 20, 30, 40, 50]) view = arr[1:4] view[1] = 99 result = arr
Changing view[1] modifies the second element of the view, which corresponds to arr[2]. This change affects the original array because the view shares data.
Fix the error in the code to create a view of the last two elements.
import numpy as np arr = np.array([5, 10, 15, 20, 25]) view = arr[1]
The slice [-2:] correctly selects the last two elements as a view. Using [-2] selects a single element, not a slice.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['data', 'is', 'fun', 'science'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension uses len(word) to get the length and filters words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 2.
words = ['apple', 'is', 'red', 'big'] result = [1]: [2] for w in words if [3]
The dictionary comprehension maps the uppercase version of each word (w.upper()) to its length (len(w)) only if the length is greater than 2 (len(w) > 2).