Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We can create a numpy array from separate lists by spec ifying a format for each field: arr = np.zeros(4, dtype={'names': ('name', 'age', 'major', 'gpa'),

We can create a numpy array from separate lists by spec ifying a format for each field: arr = np.zeros(4, dtype={'names': ('name', 'age', 'major', 'gpa'), 'formats': ('U50', 'i4', 'U4', 'f8')}) arr['name'] = ['Alice', 'Bob', 'Carol', 'Dennis'] arr['age'] = [21, 25, 18, 29] arr['major'] = ['CS', 'Math', 'Chem', 'Phys'] arr['gpa'] = [3.8, 3.2, 4.0, 3.5]

where U50 is a string of max length 50, i4 is a 4-byte integer, U4 is a string of max length 4, and f8 is an 8-byte floating-point number. Then arr has value

array([('Alice', 21, 'CS', 3.8), ('Bob', 25, 'CS', 3.2), ('Carol', 18, 'Chem', 4. ), ('Dennis', 29, 'Phys', 3.5)], dtype=[('name', '

Then, for example, arr[name] will give an array of just the student names.

Write a PYTHON program studentStats.py that reads the file roster2.dat that has this format: name,age,major,gpa

Convert this to a numpy array as shown above. Then use that array to com- pute and print each of the following: (a) The average GPA of all students (b) The maximum GPA of students majoring in CS (c) The number of students with a GPA over 3.5 (d) The average GPA of students who are at least 25 years old (e) The major that has the highest average GPA among students at most 22 years old

For example, for the four students listed, your program should print: 3.625 3.8 2 3.35 Chem

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions