Next / Previous / Contents / Shipman's homepage

3. Importing NumPy

The NumPy module provides hundreds of useful mathematical functions, as well as constants like pi (π) and e (the base of natural logarithms).

There are two ways to make these functions and constants available to your program.

3.1. Adding NumPy to your namespace

If your program is primarily doing computation, and you don't use a lot of other modules, place this statement with the other import statements at the top of your script, and it will add all the names from the NumPy module to your namespace.

from numpy import *

You can then refer directly to the constants like pi and functions like array() and arange(). Example:

>>> from numpy import *
>>> print pi, e
3.14159265359 2.71828182846
>>> print arange(0.0, 1.0, 0.1)
[ 0.   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9]