Get Started

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”

View Course

Exercise instructions

  • Import the numpy package as np, so that you can refer to numpy with np.
  • Use np.array() to create a numpy array from baseball. Name this array np_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

This exercise is part of the course

Introduction to Python

BeginnerSkill Level
4.8+
2356 reviews

Master the basics of data analysis with Python in just four hours. This online course will introduce the Python interface and explore popular packages.

NumPy is a fundamental Python package to efficiently practice data science. Learn to work with powerful tools in the NumPy array, and get started with data exploration.

Exercise 1: NumPyExercise 2: Your First NumPy Array
Exercise 3: Baseball players' heightExercise 4: NumPy Side EffectsExercise 5: Subsetting NumPy ArraysExercise 6: 2D NumPy ArraysExercise 7: Your First 2D NumPy ArrayExercise 8: Baseball data in 2D formExercise 9: Subsetting 2D NumPy ArraysExercise 10: 2D ArithmeticExercise 11: NumPy: Basic StatisticsExercise 12: Average versus medianExercise 13: Explore the baseball data

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free