Structured Arrays
A structured dtype stores named fields, like a tiny table.
Example
p = np.array([("Ada", 30), ("Kofi", 25)], dtype=[("name", "U10"), ("age", "i4")])
print(p["name"], p["age"].mean())
print(p[p["age"] > 26]["name"])Result
['Ada' 'Kofi'] 27.5 ['Ada']
Exercise
Named fields.
dtype=[("a", "")]
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.