Complete the code to reshape the array into 2 rows and 3 columns.
import numpy as np arr = np.array([1, 2, 3, 4, 5, 6]) reshaped = arr.[1]((2, 3)) print(reshaped)
The reshape method changes the shape of the array without changing its data.
Complete the code to transpose the 2D array.
import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]]) transposed = arr.[1]() print(transposed)
The transpose() method swaps the rows and columns of the array.
Fix the error in reshaping the array to 3 rows and 2 columns.
import numpy as np arr = np.array([1, 2, 3, 4, 5]) reshaped = np.[1](arr, (3, 2)) print(reshaped)
The resize method can change the size of the array and fill with repeated values if needed, allowing reshaping incompatible with original size.
Fill both blanks to create a dictionary with word lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) to get length and filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.
data = {'a': 1, 'b': -2, 'c': 3}
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
print(result)The dictionary comprehension uses k.upper() for keys, v for values, and filters values greater than 0 with >.