Recall & Review
beginner
What is a structured array in NumPy?
A structured array is a special type of NumPy array that allows you to store different data types in each element, similar to a table with columns of different types.
Click to reveal answer
beginner
How do you define the data type for a structured array in NumPy?
You define a structured array's data type using a list of tuples, where each tuple contains a field name and its data type, for example: [('name', 'U10'), ('age', 'i4')] means a string field 'name' and an integer field 'age'.
Click to reveal answer
beginner
Show how to create a structured array with fields 'name' (string) and 'age' (integer) with two entries.
Use numpy.array with dtype: np.array([('Alice', 25), ('Bob', 30)], dtype=[('name', 'U10'), ('age', 'i4')])
Click to reveal answer
beginner
How do you access the 'age' field from a structured array named 'data'?
You access it by using data['age'], which returns an array of all ages in the structured array.
Click to reveal answer
beginner
Why are structured arrays useful in data science?
They let you store and manipulate tabular data with different types efficiently, similar to a spreadsheet or database table, but with NumPy's speed and functionality.Click to reveal answer
What does the dtype [('name', 'U10'), ('age', 'i4')] specify in a structured array?
✗ Incorrect
The dtype specifies a Unicode string field 'name' with max length 10 and a 4-byte integer field 'age'.
How do you create a structured array with fields 'x' and 'y' both as floats?
✗ Incorrect
Option C correctly creates a structured array with float fields 'x' and 'y'.
How can you access the 'name' field of a structured array called 'arr'?
✗ Incorrect
You access fields in structured arrays using arr['field_name'] syntax.
What type of data can a structured array hold?
✗ Incorrect
Structured arrays can hold different data types in each field.
Which of these is a benefit of using structured arrays?
✗ Incorrect
Structured arrays efficiently store tabular data with mixed data types.
Explain how to create a structured array with fields for 'city' (string) and 'population' (integer).
Think about how to specify the dtype and how to pass data as tuples.
You got /3 concepts.
Describe how you would access and print all values of a specific field in a structured array.
Remember how to get a column from a table.
You got /3 concepts.