Question
Working with data in NumPy Program: python In this section, we're going to practice using functions and learn how NumPy can be used to write
Working with data in NumPy
Program: python
In this section, we're going to practice using functions and learn how NumPy can be used to write data.
Part 1: Create a function to calculate body mass index (BMI). BMI has been shown to be moderately correlated with total body fat and is a common measure for determining if a patient may have adverse health outcomes due to weight.
BMI=Weight (kg)/Height (m)^2
where weight is in kg and height in meters (not centimeters).
Given this equation, the function should have inputs weight and height, and then return BMI.
Part 2: Using this new function, calculate the bmi of all the children in this data set and store in a new list. Then, use the savetxt() command in NumPy to create a new data files called "bmi_all.txt" that store the bmi calculations. We're using the extension ".txt" to enforce that this is a simple text file that could be read with any text editor. Make a plot of BMI vs age to make sure the values are what you expect them to be.
Part 3: Now, read the text file you just created back into a NumPy array and call this new array bmi2. Plot bmi2 vs the original list of bmi's you created above to make sure the values are the same as before. If everything worked as intended, you should get a straight diagonal line on your plot, which indicates a direct one-to-one mapping between your original values and the values you just read in from your new text file.
Part 4: For adults (age 18-65 years), BMI's in the range of 18.5 to 24.9 kg/m22 are considered healthy. A BMI of 25.0 or more is considered overweight. Determine how many adults in this dataset are overweight.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started