Your First NumPy Array
You're now going to dive into the world of baseball. Along the way, you'll get comfortable with the basics of numpy
, a powerful package to do data science.
A list baseball
has already been defined in the Python script, representing the height of some baseball players in centimeters. Can you add some code to create a numpy
array from it?
This is a part of the course
“Introduction to Python”
Exercise instructions
- Import the
numpy
package asnp
, so that you can refer tonumpy
withnp
. - Use
np.array()
to create anumpy
array frombaseball
. Name this arraynp_baseball
. - Print out the type of
np_baseball
to check that you got it right.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import the numpy package as np
baseball = [180, 215, 210, 210, 188, 176, 209, 200]
# Create a numpy array from baseball: np_baseball
# Print out type of np_baseball