Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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?
AA string field 'name' with max length 10 and an integer field 'age'
BTwo integer fields named 'name' and 'age'
CA float field 'name' and a string field 'age'
DAn array of 10 strings and 4 integers
✗ 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?
5. You have a list of employee data: [('John', 28, 50000), ('Jane', 32, 60000), ('Doe', 24, 45000)]. How do you create a structured array with fields 'name' (string, max 10 chars), 'age' (int), and 'salary' (float) to store this data?