What is the NumPy Library?
NumPy is a Python library that allows you to perform numerical calculations. Think about linear algebra in school (or university) β NumPy is the Python library for it. Itβs about matrices and vectors β and doing operations on top of them.
Get Version Number with np.__version__
To check the NumPy version running in your script, run two commands in your shell:
- Import the library with
import numpy as np
, and - Run and print the attribute
np.__version__
to check the version of NumPy running in your script.
Here’s the code and the output version on my computer:
import numpy as np print(np.__version__)
The output in my Python script is:
1.19.2
Get Detailed Version Information with numpy.version
Alternatively, to check the NumPy version running in your script, run two commands in your shell:
- Import the library with
import numpy as np
, and - Run and print the attribute
np.version.version
to check the version of NumPy running in your script.
Here’s the code and the output version on my computer:
import numpy as np print(np.version.version)
The output in my Python script is:
1.19.2
The numpy.version
name refers to a submodule itself that is packed with lots of additional information
>>> type(np.version) <class 'module'>
For instance, the numpy.version
module can provide you even more insight as shown in the following code snippet:
import numpy as np print(np.version.version) # 1.19.2 print(np.version.short_version) # 1.19.2 print(np.version.full_version) # 1.19.2 print(np.version.git_revision) # 68752f786df542d340f25c41a8920d9b2aed66cf print(np.version.release) # True
How to Check Your NumPy Version with Pip? [Win, macOS, Linux]
To check your NumPy version with pip
in your Windows command line, Powershell, macOS terminal, or Linux shell, run pip show numpy
. The second line of the output provides your NumPy version.
PS C:\Users\xcent> pip show numpy Name: numpy Version: 1.18.4 Summary: NumPy is the fundamental package for array computing with Python. Home-page: https://www.numpy.org Author: Travis E. Oliphant et al. Author-email: None License: BSD Location: c:\users\xcent\appdata\local\programs\python\python38\lib\site-packages Requires: Required-by: seaborn, scipy, pandas, matplotlib
Here’s a screenshot on my Windows computer using Powershell:
Resources and Further Reading
You can check the newest NumPy versions here: https://pypi.org/project/numpy/#history
If you need to get a refresher on NumPy, check out my in-depth NumPy Tutorial on this Finxter blog.
If you’re really ambitious about your data science skills, check out our in-depth book Coffee Break NumPy (Amazon Link).