Complete the code to sort the array in ascending order.
import numpy as np arr = np.array([3, 1, 4, 1, 5]) sorted_arr = np.[1](arr) print(sorted_arr)
The np.sorted() function returns a sorted copy of the array.
Complete the code to get the indices that would sort the array.
import numpy as np arr = np.array([10, 2, 8, 6]) indices = np.[1](arr) print(indices)
np.argsort() returns the indices that would sort the array.
Fix the error in the code to sort the array in descending order.
import numpy as np arr = np.array([7, 3, 9, 1]) sorted_arr = np.sort(arr)[1][::-1] print(sorted_arr)
No operator is needed between np.sort(arr) and [::-1]. The slice directly reverses the sorted array.
Fill both blanks to create a dictionary of word lengths for words longer than 3 letters.
words = ['data', 'is', 'fun', 'and', 'powerful'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) for values and filters words with length greater than 3.
Fill all three blanks to create a dictionary with uppercase keys and values for words longer than 2 letters.
words = ['cat', 'is', 'big', 'and', 'red'] result = [1]: [2] for w in words if len(w) [3] 2 print(result)
The dictionary comprehension uses uppercase words as keys, original words as values, and filters words longer than 2 letters.