Complete the code to stack arrays vertically using numpy.
import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5, 6]) result = np.[1]([arr1, arr2]) print(result)
np.vstack() stacks arrays vertically (row-wise), creating a 2D array with arr1 and arr2 as rows.
Complete the code to stack arrays horizontally using numpy.
import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5, 6]) result = np.[1]([arr1, arr2]) print(result)
np.hstack() stacks arrays horizontally (column-wise), joining arr1 and arr2 side by side.
Fix the error in the code to stack two 2D arrays vertically.
import numpy as np arr1 = np.array([[1, 2], [3, 4]]) arr2 = np.array([[5, 6]]) result = np.[1]([arr1, arr2]) print(result)
np.vstack() stacks arrays vertically. Here arr2 has one row, so vertical stacking works.
Fill both blanks to create a dictionary of word lengths for words longer than 3 letters.
words = ['cat', 'house', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
We use len(word) to get length and filter words with length greater than 3.
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)Keys are converted to uppercase with k.upper(), values are v, and filter keeps values greater than 0.