Question: Python Question - Numpy No Loops, please. Use only Numpy to solve the question below. A common practice in doing array-based data analysis is to

Python Question - Numpy

No Loops, please. Use only Numpy to solve the question below.

A common practice in doing array-based data analysis is to keep metadata separate from the actual numeric data. Metadata consists of items such as field names, descriptions, etc. For example, the file teams.csv (pasted below) contains a list of team names and the file winloss.csv (pasted below) contains information about the teams' records throughout the season. For example, the Owls won their game against the Cubs because of line 3, column 5 of the file contains a W. Note the diagonal has X values because teams don't play themselves (obviously!). Write a function named final_results that accepts two parameters: a teams file name and a win/loss file name. Your function should load each file into a ndarray and return a tuple consisting of two parallel ndarrays: one with team names and one with total wins for each team. The arrays should be sorted with the most wins first. Here is an example call (with the two files linked above):

In [1]: final_results('teams.csv','winloss.csv') Out[1]: (array(['Rams', 'Cubs', 'Jazz', 'Owls', 'Jets', 'Zips'], dtype='|S4'), array([4, 3, 3, 2, 2, 1]))

Please find below the teams.csv file:

Jazz
Jets
Owls
Rams
Cubs
Zips

Please find also the winloss.csv file:

X W W L L W
L X W W L L
L L X L W W
W L W X W W
W W L L X W
L W L L L X

In this example result, the Rams won the season with 4 wins. The Cubs and Jazz both had 3, Owls and Jets had 2, etc. In general, element i of the teams result corresponds to element i of the wins result. Note that the team with the most wins appears first, and the team with the least wins appears at the end of the array. As usual, stick to NumPy functions and do not use any loops in your function.

Point of Stress: Please attached a print screen in addition to the codes as evidence that the scripts ran properly and as intended. Thank you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!