NumPy, SciPy and SciKits
Jump to navigation
Jump to search
Python provides a framework on which numerical and scientific data processing can be built. As part of our short course on Python for Physics and Astronomy we will look at the capabilities of the NumPy, SciPy and SciKits packages. This is a brief overview with a few examples drawn primarily from the excellent but short introductory book SciPy and NumPy by Eli Bressert (O'Reilly 2012).
NumPy
NumPy adds arrays and linear albegra to Python, with special functions, transformations, the ability to operate on all elements of an array in one stroke.
Arrays are at the heart of NumPy. The program
import numpy as np mylist = [1, 3, 5, 7, 11, 13] myarray = np.array(mylist) print myarray
creates a list and makes an array from it. You can create an array of 30 32-bit floating point zeros with
myarray = np.zeros(30, dtype=np.float32)
The dtype argument is optional and can be
- unit8, 16, 32, 64
- int8, 16, 32, 64
- float32, 64, 128
- complex64, 128