Complete the code to sort the 1D numpy array in ascending order.
import numpy as np arr = np.array([3, 1, 4, 2]) sorted_arr = np.sort([1]) print(sorted_arr)
The np.sort() function sorts the array passed to it. Here, arr is the array to sort.
Complete the code to sort the 2D numpy array along axis 0 (columns).
import numpy as np arr = np.array([[3, 2], [1, 4]]) sorted_arr = np.sort(arr, axis=[1]) print(sorted_arr)
Sorting along axis 0 means sorting each column. So, axis=0 is correct.
Fix the error in the code to sort the 2D array along axis 1 (rows).
import numpy as np arr = np.array([[5, 3], [2, 4]]) sorted_arr = np.sort(arr, axis=[1]) print(sorted_arr)
Axis 1 sorts each row independently in a 2D array.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = { [1] : [2] for word in words if len(word) > 3 } print(lengths)
word.upper() or word.lower() as keys instead of the original word.The dictionary keys are the words themselves, and the values are their lengths using len(word).
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, but only for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = { [1] : [2] for word in words if len(word) [3] 3 } print(lengths)
Keys are uppercase words using word.upper(), values are lengths, and the condition filters words longer than 3 letters with >.