1.2 The Python Numerical Extension modules

The Numeric and numarray modules extend Python with multi-dimensional array types and a complete set of 'standard' functions and operators to manipulate the arrays.

Python together with at least one of those modules is an ideal language experimental numerical and scientific computing (as powerful as APL, MatLab, IDL and others, but much more elegant).

If you do not have a mathematical background, you can think of those array types as columns in a spreadsheet. The spreadsheet lets you do operations on whole columns at once. Look at the following simple example:

>>> from Numeric import * # 1 >>> x = arange(0.0, 10.0, 3.0) # 2 >>> y = sin(x) # 3 >>> x # 4 array([ 0., 3., 6., 9.]) # 5 >>> y # 6 array([ 0. , 0.14112001, -0.2794155 , 0.41211849]) # 7 >>> sqrt(x*x) # 8 array([ 0., 3., 6., 9.]) # 9 >>> x*x # 10 array([ 0., 9., 36., 81.]) # 11

The function call "`arange(0.0, 10.0, 3.0)`" returns a NumPy array of 4
equidistant points from 0 to 9 inclusive: "`array([ 0., 3., 6., 9.])`".
The function call "`sin(x)`" and statement "`x*x`" show that
"`sin`" and "`*`" manipulate NumPy arrays element by element.
All this in C, for a manifold speedup with respect to pure Python.