Previous Page
Next Page

16.6. Auxiliary Numeric Modules

Many other modules are built on top of Numeric or cooperate with it. Some of these extra modules are included in the Numeric package, and their documentation is also part of Numeric's documentation. A rich collection of scientific and engineering computing tools that work with Numeric is available at; have a look at it if you are using Python for any kind of scientific or engineering computing.

Here are the key auxiliary modules that come with Numeric:


MLab supplies many Python functions, written on top of Numeric, but is similar in name and operation to functions supplied by the product Matlab.


FFT supplies Python-callable Fast Fourier Transforms (FFTs) of data held in Numeric arrays. FFT can wrap either the well-known FFTPACK Fortran-coded library or the compatible C-coded fftpack library, which comes with FFT.


LinearAlgebra supplies Python-callable functions, operating on data held in Numeric arrays, wrapping either the LAPACK Fortran-coded library or the compatible C-coded lapack_lite library. LinearAlgebra lets you invert matrices, solve linear systems, compute eigenvalues and eigenvectors, perform singular value decomposition, and least-squares-solve overdetermined linear systems.


RandomArray supplies fast, high-quality pseudorandom number generators to build Numeric arrays with various random distributions.


MA supports masked arrays (i.e., arrays that can have missing or invalid values). MA supplies a large subset of Numeric's functionality, albeit sometimes at reduced speed. MA also lets you associate to each array an optional mask, which is an auxiliary array of Booleans, where TRue indicates array elements that are missing, unknown, or invalid. Computations propagate masks; you can turn masked arrays into plain Numeric ones by supplying a fill-in value for invalid elements. MA is widely applicable because experimental data often has missing or inapplicable elements. Should you need to extend or specialize some aspect of Numeric's behavior for your application's purposes, it may be simplest and most effective to start with MA's sources rather than with Numeric's. The latter are often quite hard to understand and modify due to the degree of optimization applied to them over the years.

These modules' performance is generally quite good. For example:

import RandomArray x = RandomArray.random((13,23))

On my laptop, this takes 109 microseconds. The pure-Python equivalent:

from random import random x = [[random( ) for i in xrange(13)] for j in xrange(23)]

takes 230 microseconds, over twice as long.

Previous Page
Next Page