Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Print out a numpy array with the BMIs of all players whose BMI is below 21

Use light inside square brackets to do a selection on the bmi array.

import numpy as np
Calculate the BMI: bmi
np_height_m = np.array(height_in) * 0.0254
np_weight_kg = np.array(weight_lb) * 0.453592
bmi = np_weight_kg / np_height_m ** 2
print(bmi)
Create the light array
light = bmi<21
Print out light
print(light)
Print out BMIs of all baseball players whose BMI is below 21
bmi[light<21]

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

light is an array of booleans. You should use it directly to slice:

bmi[light]

When you run:

bmi[light<21]  # equivalent to bmi[(bmi<21)<21]

This compares the booleans to 21, which is always True as True equals 1 and False equals 0. This thus yields all elements.

Of note, you don’t need the intermediate light array, you could use directly:

bmi[bmi<21]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading