Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please explain just part C def part_b(filename:str='data/pokemon.txt'): II III Consider only those Pokemon STRICTLY heavier than the median weight. For these Pokemon, compute the proportion

image text in transcribed

image text in transcribedPlease explain just part "C"

image text in transcribed

image text in transcribed

image text in transcribed

def part_b(filename:str='data/pokemon.txt'): II III Consider only those Pokemon STRICTLY heavier than the median weight. For these Pokemon, compute the proportion of Pokemon that are legendary, the average height, the average weight, the average encounter_prob, and average catch_prob. :param filename: The path to the csv as described in the pset. :return: A numpy array of length 5 with these 5 quantities. Hint(s): 1. Use np.median(...) to compute medians along an axis. 2. Use np.where(...) to select only certain rows. II II II import numpy as np The data for this problem is provided in pokemon.txt and follows the following format. Col 1: pokemon_id: A unique identifier for the Pokemon. Col 2: is_legendary: A 1 if the Pokemon is legendary, and o otherwise. Col 3: height: The height of the Pokemon in meters. Col 4: weight: The weight of the Pokemon in kilograms. Col 5: encounter_prob: The probability of encountering this Pokemon in the wild grass. Note the sum of this entire column is i, since when you make an encounter, exactly one of these Pokemon appears. Col 6: catch_prob: Once you have encountered a Pokemon, the probability you catch it. (Ignore any mechanics of the actual game if you've played a Pokemon game in the past.) II III def part_a(filename:str='data/pokemon.txt'): Compute the proportion of Pokemon that are legendary, the average height, the average weight, the average encounter_prob, and average catch_prob. :param filename: The path to the csv as described in the pset. :return: A numpy array of length 5 with these 5 quantities. Hint(s): 1. Use np.genfromtxt(...) to load the file. Do NOT hardcode 'data/pokemon.txt' as the parameter as we may use other hidden files to test your function. 2. Use np.mean(...) with its axis parameter to compute means in one line. II II 11 (Coding] Let's learn how to use Python and data to do approximate quantities that are hard to compute exactly! By the end of this, we'll see how long it actually takes to catchem all! You are given a file pokemon.txt which contains information about several (fictional) Pokemon, such as their encounter rate and catch rate. Write your code for the following parts in the provided file: pokemon.py. (a) Implement the function part_a. (b) Implement the function part_b. (c) Implement the function part_c. . (d) Implement the function part_d. 1 000 77.2464 11.5633 0.1029 0.9338 2 01 O 2.5648 30.6601 0.0762 0.8374 3020 63.5480 0.0396 0.0916 0.9689 4 03 0 75.0060 7.1783 0.1117 0.7685 5 04 050.1014 16.7462 0.0962 0.6908 6 05 0 22.8673 9.4811 0.0957 0.7622 7 06 1 20.2073 12.7925 0.1079 0.6988 8 07 0 76.1728 3.4514 0.1009 0.9418 9 08 0 17.3265 24.9829 0.1101 0.6759 10 09 1 9.2898 12.5378 0.1068 0.8729 def part_c(filename: str='data/pokemon.txt', ntrials:int=5000): II II 11 Suppose you are walking around the wild grass, and you wonder: how many encounters do you expect to make until you ENCOUNTER each Pokemon (at least) once? :param filename: The path to the csv as described in the pset. :param ntrials: How many simulations to run. :return: The (simulated) average number of ENCOUNTERS you expect to make, until you ENCOUNTER each Pokemon (at least) once. Hint(s): 1. You only need to use one of the columns for this part! 2. You may want to use np.random.choice(...) with the parameter a being np.arange (...) and the parameter p being the data column! def sim_one(): This is a nested function only accessible by parent part_c, which we're in now. You may want to implement this function! pass pass # TODO: Your code here (10-20 lines)

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

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions