NumPy Getting Started

Lesson 2 of 17

Before writing NumPy code you need NumPy installed and imported. It takes a minute, and on many setups it is already done for you.

Install NumPy

If you have Python and pip, install NumPy from the command line:

Bash
pip install numpy

Using Anaconda? NumPy is already included. You can also install or update it with conda:

Bash
conda install numpy

Google Colab and most Jupyter setups ship with NumPy, so you can skip installation there.

Import NumPy

Import NumPy with the import keyword. By convention it is imported under the alias np, and you will see this alias in almost all NumPy code:

Example

Python
import numpy as np

arr = np.array([1, 2, 3, 4, 5])
print(arr)

Output

Plain Text
[1 2 3 4 5]

An alias is just a shorter name. After import numpy as np you write np.array() instead of numpy.array().

Check the NumPy version

The installed version is stored in __version__:

Example

Python
import numpy as np

print(np.__version__)

Output

Plain Text
2.3.5

Your version may be different. Everything in this course works on current NumPy releases.