Baseball data in 2D form
You realize that it makes more sense to restructure all this information in a 2D numpy
array.
You have a Python list of lists. In this list of lists, each sublist represents the height and weight of a single baseball player. The name of this list is baseball
and it has been loaded for you already (although you can't see it).
Store the data as a 2D array to unlock numpy
's extra functionality.
This exercise is part of the course
Introduction to Python
Exercise instructions
- Use
np.array()
to create a 2Dnumpy
array frombaseball
. Name itnp_baseball
. - Print out the
shape
attribute ofnp_baseball
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
import numpy as np
# Create a 2D numpy array from baseball: np_baseball
np_baseball =
# Print out the shape of np_baseball