Complete the code to create a structured numpy array with fields 'name' and 'age'.
import numpy as np data = np.array([('Alice', 25), ('Bob', 30)], dtype=[1])
The dtype for a structured array must be a list of tuples specifying field names and types.
Complete the code to find the union of two structured numpy arrays 'a' and 'b'.
import numpy as np a = np.array([(1, 'A'), (2, 'B')], dtype=[('id', 'i4'), ('val', 'U1')]) b = np.array([(2, 'B'), (3, 'C')], dtype=[('id', 'i4'), ('val', 'U1')]) union = np.[1](a, b)
np.union1d returns the sorted unique values that are in either of the input arrays.
Fix the error in the code to find the intersection of two structured arrays 'x' and 'y'.
import numpy as np x = np.array([(1, 10), (2, 20)], dtype=[('id', 'i4'), ('score', 'i4')]) y = np.array([(2, 20), (3, 30)], dtype=[('id', 'i4'), ('score', 'i4')]) common = np.[1](x, y)
np.intersect1d returns the sorted unique values that are in both arrays.
Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
words = ['data', 'science', 'ai', 'ml'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension maps each word to its length if the length is greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their values only if the value is greater than 0.
data = {'a': 1, 'b': -1, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0}The comprehension maps uppercase keys to their values only if the value is positive.