Baseball players' height
You are a huge baseball fan. You decide to call the MLB (Major League Baseball) and ask around for some more statistics on the height of the main players. They pass along data on more than a thousand players, which is stored as a regular Python list: height_in
. The height is expressed in inches. Can you make a numpy
array out of it and convert the units to meters?
height_in
is already available and the numpy
package is loaded, so you can start straight away (Source: stat.ucla.edu).
This exercise is part of the course
Introduction to Python
Exercise instructions
- Create a
numpy
array fromheight_in
. Name this new arraynp_height_in
. - Print
np_height_in
. - Multiply
np_height_in
with0.0254
to convert all height measurements from inches to meters. Store the new values in a new array,np_height_m
. - Print out
np_height_m
and check if the output makes sense.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import numpy
import numpy as np
# Create a numpy array from height_in: np_height_in
# Print out np_height_in
# Convert np_height_in to m: np_height_m
# Print np_height_m