Before we explore the world of image manipulation as a case-study in array manipulation, we should first define a few terms which we'll use over and over again. Discussions of arrays and matrices and vectors can get confusing due to differences in nomenclature. Here is a brief definition of the terms used in this tutorial, and more or less consistently in the error messages of numarray.
The Python objects under discussion are formally called `` NumArray'' (or even more correctly ``numarray'') objects (N-dimensional arrays), but informally we'll just call them ``array objects'' or just ``arrays''. These are different from the array objects defined in the standard Python array module (which is an older module designed for processing one-dimensional data such as sound files).
These array objects hold their data in a fixed length, homogeneous (but not necessarily contiguous) block of elements, i.e. their elements all have the same C type (such as a 64-bit floating-point number). This is quite different from most Python container objects, which are variable length heterogeneous collections.
Any given array object has a rank, which is the number of
``dimensions'' or ``axes'' it has. For example, a point in 3D space
2, 1] is an array of rank 1 -- it has one dimension. That dimension has a
length of 3. As another example, the array
1.0 0.0 0.0 0.0 1.0 2.0
axis=-1is the last axis of an array,
axis=-2is the penultimate axis, etc.
There are there important and potentially unintuitive behaviors of numarray arrays which take some getting used to. The first is that by default, operations on arrays are performed elementwise.4.1 This means that when adding two arrays, the resulting array has as elements the pairwise sums of the two operand arrays. This is true for all operations, including multiplication. Thus, array multiplication using the * operator will default to elementwise multiplication, not matrix multiplication as used in linear algebra. Many people will want to use arrays as linear algebra-type matrices (including their rank-1 versions, vectors). For those users, the matrixmultiply function will be useful.
The second behavior which will catch many users by surprise is that certain operations, such as slicing, return arrays which are simply different views of the same data; that is, they will in fact share their data. This will be discussed at length in examples later. Now that these definitions and warnings are laid out, let's see what we can do with these arrays.
The third behavior which may catch Matlab or Fortran users unaware is the use of row-major data storage as is done in C. So while a Fortran array might be indexed a[x,y], numarray is indexed a[y,x].