Recall & Review
beginner
What is a structured array in NumPy?
A structured array is a NumPy array that can hold different data types in named fields, like columns in a table.
Click to reveal answer
beginner
How do you access a field named 'age' in a structured NumPy array called 'data'?
You use data['age'] to get all values in the 'age' field.
Click to reveal answer
beginner
Why is accessing fields by name useful in NumPy structured arrays?
It lets you work with specific columns easily without affecting other data, similar to selecting a column in a spreadsheet.
Click to reveal answer
intermediate
Can you assign new values to a field in a NumPy structured array? How?
Yes, by using data['field_name'] = new_values, you can update the values in that field.
Click to reveal answer
intermediate
What happens if you try to access a field name that does not exist in a NumPy structured array?
NumPy raises a ValueError because the field name is not found in the array's dtype.
Click to reveal answer
How do you access the 'height' field in a structured NumPy array named 'people'?
✗ Incorrect
In NumPy structured arrays, fields are accessed using square brackets and the field name as a string.
What type of object is returned when you access a field by name in a structured array?
✗ Incorrect
Accessing a field returns a NumPy array containing all values for that field.
If 'data' is a structured array, what does data['age'] = 30 do?
✗ Incorrect
Assigning a value to a field updates all entries in that field.
What error occurs if you try to access a non-existent field in a structured array?
✗ Incorrect
Accessing a missing field raises a ValueError.
Which of these is NOT a valid way to access fields in a NumPy structured array?
✗ Incorrect
NumPy structured arrays do not have a .get() method for accessing fields. Use array['field'] or array.field.
Explain how to access and update a field named 'score' in a NumPy structured array.
Think about how you select columns in a table.
You got /3 concepts.
Describe what happens if you try to access a field that does not exist in a structured array.
What error do you get when a key is missing in a dictionary?
You got /3 concepts.