Complete the code to create a structured array with fields 'name' and 'age'.
import numpy as np data = np.array([('Alice', 25), ('Bob', 30)], dtype=[1]) print(data)
The dtype defines the structure with a string field 'name' of length 10 and an integer field 'age'.
Complete the code to access the 'age' field from the structured array.
ages = data[1] print(ages)
Accessing a field in a structured array is done by indexing with the field name as a string.
Fix the error in the code to create a structured array with fields 'x' and 'y' as floats.
points = np.array([(1.0, 2.0), (3.0, 4.0)], dtype=[1]) print(points)
Using 'f8' means 8-byte float (double precision), which matches the float values given.
Fill both blanks to create a structured array with fields 'id' as integer and 'score' as float.
results = np.array([(1, 95.5), (2, 88.0)], dtype=[[1], [2]]) print(results)
The dtype list must contain tuples defining each field name and its data type.
Fill all three blanks to create a structured array with fields 'name' (string), 'age' (int), and 'height' (float).
people = np.array([
('John', 28, 5.9),
('Jane', 32, 5.5)
], dtype=[[1], [2], [3]])
print(people)The dtype list defines each field with its name and data type matching the data.