Complete the code to join two numpy arrays along the default axis.
import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5, 6]) result = np.concatenate((arr1, arr2), axis=[1]) print(result)
The default axis for concatenation of 1D arrays is 0, which joins them end-to-end.
Complete the code to join two 2D numpy arrays vertically.
import numpy as np arr1 = np.array([[1, 2], [3, 4]]) arr2 = np.array([[5, 6], [7, 8]]) result = np.concatenate((arr1, arr2), axis=[1]) print(result)
Axis 0 means stacking arrays vertically (row-wise) for 2D arrays.
Fix the error in the code to concatenate two arrays along columns.
import numpy as np arr1 = np.array([[1, 2], [3, 4]]) arr2 = np.array([[5, 6], [7, 8]]) result = np.concatenate((arr1, arr2), axis=[1]) print(result)
Axis 1 means concatenating arrays side by side (column-wise) for 2D arrays.
Fill both blanks to create a dictionary with word lengths for words longer than 3 letters.
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) as value and filters 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)The dictionary comprehension uses uppercase keys, values v, and filters values greater than 0.