Knowee
Questions
Features
Study Tools

Using %mprun: Hero BMIYou'd like to calculate the body mass index (BMI) for a selected sample of heroes. BMI can be calculated using the below formula:A random sample of 25,000 superheroes has been loaded into your session as an array called sample_indices. This sample is a list of indices that corresponds to each superhero's index selected from the heroes list.A function named calc_bmi_lists has also been created and saved to a file titled bmi_lists.py. For convenience, it is displayed below:def calc_bmi_lists(sample_indices, hts, wts): # Gather sample heights and weights as lists s_hts = [hts[i] for i in sample_indices] s_wts = [wts[i] for i in sample_indices] # Convert heights from cm to m and square with list comprehension s_hts_m_sqr = [(ht / 100) ** 2 for ht in s_hts] # Calculate BMIs as a list with list comprehension bmis = [s_wts[i] / s_hts_m_sqr[i] for i in range(len(sample_indices))] return bmisNotice that this function performs all necessary calculations using list comprehension (hence the name calc_bmi_lists()). Dig deeper into this function and analyze the memory footprint for performing your calculations using lists:Load the memory_profiler package into your IPython session.Import calc_bmi_lists from bmi_lists.Once you've completed the above steps, use %mprun to profile the calc_bmi_lists() function acting on your superheroes data. The hts array and wts array have already been loaded into your session.After you've finished coding, answer the following question:How much memory do the list comprehension lines of code consume in the calc_bmi_lists() function? (i.e., what is the total sum of the Increment column for these four lines of code?)

Question

Using %mprun: Hero BMIYou'd like to calculate the body mass index (BMI) for a selected sample of heroes. BMI can be calculated using the below formula:A random sample of 25,000 superheroes has been loaded into your session as an array called sample_indices. This sample is a list of indices that corresponds to each superhero's index selected from the heroes list.A function named calc_bmi_lists has also been created and saved to a file titled bmi_lists.py. For convenience, it is displayed below:def calc_bmi_lists(sample_indices, hts, wts): # Gather sample heights and weights as lists s_hts = [hts[i] for i in sample_indices] s_wts = [wts[i] for i in sample_indices] # Convert heights from cm to m and square with list comprehension s_hts_m_sqr = [(ht / 100) ** 2 for ht in s_hts] # Calculate BMIs as a list with list comprehension bmis = [s_wts[i] / s_hts_m_sqr[i] for i in range(len(sample_indices))] return bmisNotice that this function performs all necessary calculations using list comprehension (hence the name calc_bmi_lists()). Dig deeper into this function and analyze the memory footprint for performing your calculations using lists:Load the memory_profiler package into your IPython session.Import calc_bmi_lists from bmi_lists.Once you've completed the above steps, use %mprun to profile the calc_bmi_lists() function acting on your superheroes data. The hts array and wts array have already been loaded into your session.After you've finished coding, answer the following question:How much memory do the list comprehension lines of code consume in the calc_bmi_lists() function? (i.e., what is the total sum of the Increment column for these four lines of code?)

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

To answer the question, you need to follow these steps:

  1. Load the memory_profiler package into your IPython session. You can do this by running the command %load_ext memory_profiler in your IPython session.

  2. Import the calc_bmi_lists function from the bmi_lists module. You can do this by running the command from bmi_lists import calc_bmi_lists.

  3. Use the %mprun magic command to profile the calc_bmi_lists() function. You can do this by running the command %mprun -f calc_bmi_lists calc_bmi_lists(sample_indices, hts, wts).

After running these commands, you will see a table output from the %mprun command. This table includes a column labeled 'Increment', which shows the change in memory usage after each line of code is executed.

To answer the question, you need to add up the 'Increment' values for the lines of code that involve list comprehension. These are the lines that gather sample heights and weights, convert heights from cm to m and square them, and calculate BMIs.

Please note that the actual memory consumption can vary depending on your specific data and environment. Therefore, it's not possible to provide a specific number as the answer to your question without running the code.

This problem has been solved

Similar Questions

A random sample of 25,000 superheroes has been loaded into your session as an array called sample_indices. This sample is a list of indices that corresponds to each superhero's index selected from the heroes list.A function named calc_bmi_lists has also been created and saved to a file titled bmi_lists.py. For convenience, it is displayed below:def calc_bmi_lists(sample_indices, hts, wts): # Gather sample heights and weights as lists s_hts = [hts[i] for i in sample_indices] s_wts = [wts[i] for i in sample_indices] # Convert heights from cm to m and square with list comprehension s_hts_m_sqr = [(ht / 100) ** 2 for ht in s_hts] # Calculate BMIs as a list with list comprehension bmis = [s_wts[i] / s_hts_m_sqr[i] for i in range(len(sample_indices))] return bmisNotice that this function performs all necessary calculations using list comprehension (hence the name calc_bmi_lists()). Dig deeper into this function and analyze the memory footprint for performing your calculations using lists:Load the memory_profiler package into your IPython session.Import calc_bmi_lists from bmi_lists.Once you've completed the above steps, use %mprun to profile the calc_bmi_lists() function acting on your superheroes data. The hts array and wts array have already been loaded into your session.After you've finished coding, answer the following question:How much memory do the list comprehension lines of code consume in the calc_bmi_lists() function? (i.e., what is the total sum of the Increment column for these four lines of code?)

Create a function of name get_bmi() that receive the weight in kilograms and height in centimeter of a person and return his or her Body Mass index (BMI). The function should convert the height to meters before calculating the BMI.Height in meter = height in centimeter / 100BMI = weight in kilogram / (height in meter * height in meter)For example:Test Resultprint("BMI value:", round(get_bmi(60, 160),1))BMI value: 23.4print("BMI value:", round(get_bmi(85, 170),1))BMI value: 29.4

Use np_height_m and np_weight_kg to calculate the BMI of each player. Use the following equation: BMI=weight(kg)height(m)2Save the resulting numpy array as bmi

Given height and weight of a person in float, calculate Body Mass index of the person and print respective output based on calculation. Formulae for calculation: [weight (kg) / height (cm) / height (cm)] x 10,000 .For Example: weight =76.7 , height=162.2 BMI=((76.7/162.2)/162.2)X 10,000BMI=(0.4728/162.2)X 10,000 BMI=0.000291X 10,000 BMI=29.1 So, it is Overweight.Print "Underweight" or "Healthy weight" or "Overweight" or "Obesity". Below 18.5        Underweight 18.5 – 24.9        Healthy weight 25.0 – 29.9       Overweight 30.0 and Above      ObesityInput Format:Accept two inputs, weight(float) and height(float)Output Format:Print "Underweight" or "Healthyweight" or "Overweight" or "Obesity"Constraints:1<=N<=10^15Sample Input 1:46.5 165.3Sample Output 1:UnderweightSample Input 2:76.7 162.2Sample Output 2:Overweight

Traceback (most recent call last): File "main.py", line 8, in <module> bmi = height / (weight * weight)TypeError: can't multiply sequence by non-int of type 'str'

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.