Table of Contents

Numpy, Scipy and Matplotlib

There are numerous scientific programs, packages and libraries written in various programming languages:

Mathematica, Maple, Matlab, Root, R, Numerical Recipes, etc

For python the de-facto standard are the Numpy, Scipy and Matplotlib packages. They allow to combine the ease and flexibility of Python programming with efficient and powerful libraries, which provide state-of-the art functionality and fast execution also for large applications.

NumPy

Applications in Science and Physics often require very cpu-intensive operations, e.g:

Rich legacy of numerical libraries written e.g. in Fortran or C/C++ (e.g. Numerical Recipes). This is also used with numpy, which offers an interface to BLAS (Basic Linear Algebra Library) and ATLAS (Automatically Tuned Linear Algebra Software).

Moreover, numpy offers a very efficient Array-Datatype ndarray which provides a homogenous store for numerical data types and operations and functions for it. The backend is written in C and allows efficient vectorised or parallelized operations on large array structures.

Numpy arrays

The basis of numpy is the ndarray, this is a homogenous array especially for numerical data types.

Memory layout - Python list vs numpy ndarray

Array Memory Layout

Creating arrays

Numpy datatypes

In most cases Python/numpy automatically identifies suitable data-type, though sometimes it can be useful to explicitly specify the desired type.

Here the list of supported types:

Data type Description
bool_ Boolean (True or False) stored as a byte
int_ Default integer type (same as C long; normally either int64 or int32)
intc Identical to C int (normally int32 or int64)
intp Integer used for indexing (same as C ssize_t; normally either int32 or int64)
int8 Byte (-128 to 127)
int16 Integer (-32768 to 32767)
int32 Integer (-2147483648 to 2147483647)
int64 Integer (-9223372036854775808 to 9223372036854775807)
uint8 Unsigned integer (0 to 255)
uint16 Unsigned integer (0 to 65535)
uint32 Unsigned integer (0 to 4294967295)
uint64 Unsigned integer (0 to 18446744073709551615)
float_ Shorthand for float64.
float16 Half precision float: sign bit, 5 bits exponent, 10 bits mantissa
float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa
float64 Double precision float: sign bit, 11 bits exponent, 52 bits mantissa
complex_ Shorthand for complex128.
complex64 Complex number, represented by two 32-bit floats
complex128 Complex number, represented by two 64-bit floats

Working with numpy arrays

numpy ufuncs

See here for detailed list of Numpy functions: https://scipy.github.io/old-wiki/pages/Numpy_Example_List_With_Doc.html

Array indexing and slicing

As for Python lists there are many sophisticated ways how to access or extract elements or sub-arrays

Array filtering

Array IO

Basic statistics

Linear Algebra

Solving system of equations

numpy - many more features