Complete the code to sort the array using numpy.
import numpy as np arr = np.array([3, 1, 2]) sorted_arr = np.[1](arr) print(sorted_arr)
The np.sort() function sorts the array and returns a new sorted array.
Complete the code to sort the 2D array along rows (axis=1).
import numpy as np arr = np.array([[3, 2, 1], [6, 5, 4]]) sorted_arr = np.sort(arr, axis=[1]) print(sorted_arr)
Setting axis=1 sorts each row individually.
Fix the error in the code to sort the array in-place.
import numpy as np arr = np.array([3, 1, 2]) arr.[1]() print(arr)
sorted() which returns a list, not sorting in-place.np.sort() as a method on the array.The sort() method sorts the array in-place, changing the original array.
Fill both blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 letters.
words = ['cat', 'elephant', 'dog', 'horse'] lengths = {word: [1] for word in words if [2] print(lengths)
The dictionary comprehension uses len(word) as values and filters words with length greater than 3.
Fill all three blanks to create a dictionary with uppercase words as keys, their lengths as values, only for words longer than 3 letters.
words = ['cat', 'elephant', 'dog', 'horse'] lengths = [1]: [2] for word in words if [3] print(lengths)
The dictionary comprehension uses uppercase words as keys, their lengths as values, and filters words longer than 3 letters.