NumPy arrays

Efficient arrays for numerical computing
from Numeric import *     # classical, widely used module
from numarray import *    # alternative version
a = array([[1, 4], [2, 1]], Float)  # 2x2 array from list
a = zeros((n,n), Float)             # nxn array with 0
Indexing and slicing:
for i in xrange(a.shape[0]):
    for j in xrange(a.shape[1]):
        a[i,j] = ...
b = a[0,:]  # reference to 1st row
b = a[:,1]  # reference to 2nd column
Avoid loops and indexing, use operations that compute with whole arrays at once (in efficient C code)

previousnexttable of contents