0
0
NumPydata~10 mins

Accessing fields by name in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access the 'age' field from the structured array.

NumPy
ages = data['[1]']
Drag options to blanks, or click blank then click option'
Aages
Bage
Cdata
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field name.
Trying to access fields with dot notation instead of brackets.
2fill in blank
medium

Complete the code to get the 'score' field from the structured array.

NumPy
scores = data['[1]']
Drag options to blanks, or click blank then click option'
Ascore
Bscores
Cvalue
DScore
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect capitalization.
Using plural form when the field is singular.
3fill in blank
hard

Fix the error in accessing the 'height' field from the structured array.

NumPy
heights = data[1]'height']
Drag options to blanks, or click blank then click option'
A[
B.
C('
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation instead of brackets.
Missing the opening bracket.
4fill in blank
hard

Fill both blanks to create a dictionary of names and ages from the structured array.

NumPy
result = {data['[1]'][i]: data['[2]'][i] for i in range(len(data))}
Drag options to blanks, or click blank then click option'
Aname
Bage
Cscore
Dheight
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping keys and values.
Using incorrect field names.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase names and their scores if the score is above 80.

NumPy
result = {data['[1]'][i].upper(): data['[2]'][i] for i in range(len(data)) if data['[3]'][i] > 80}
Drag options to blanks, or click blank then click option'
Aname
Bscore
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using different fields for keys and values.
Not filtering scores correctly.