Complete the code to access the element in the 2D array at row 1, column 2.
import numpy as np arr = np.array([[10, 20, 30], [40, 50, 60]]) element = arr[[1]] print(element)
To access an element in a 2D numpy array, use arr[row, column]. Here, row 1 and column 2 gives the element 60.
Complete the code to extract the entire second row from the 2D array.
import numpy as np arr = np.array([[5, 10, 15], [20, 25, 30], [35, 40, 45]]) row = arr[[1]] print(row)
Rows are indexed starting at 0. The second row is at index 1.
Fix the error in the code to correctly access the element at row 0, column 1.
import numpy as np arr = np.array([[7, 8, 9], [10, 11, 12]]) element = arr[[1]] print(element)
Use comma-separated indices inside square brackets to access elements in numpy arrays: arr[0, 1].
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 characters.
words = ['cat', 'house', 'dog', 'elephant'] lengths = {word: [1] for word in words if [2] print(lengths)
Use len(word) to get the length, and filter words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 4 characters.
words = ['apple', 'bat', 'carrot', 'dog'] result = { [1]: [2] for w in words if [3] } print(result)
Use w.upper() for keys, len(w) for values, and filter words with length greater than 4 using len(w) > 4.