3.4 Differences between numarray and Numeric.

This new version was developed for a number of reasons. To summarize, we regularly deal with large datasets and the new version gives us the capabilities that we feel are necessary for working with such datasets. In particular:

  1. Avoid promotion of array types in expressions involving Python scalars (e.g., 2.*<Float32 array> should not result in a Float64 array).
  2. Ability to use memory mapped files (largely implemented).
  3. Ability to access fields in arrays of records as numeric arrays without copying the data to a new array.
  4. Ability to reference byteswapped data or non-aligned data (as might be found in record arrays) without producing new temporary arrays.
  5. Reuse temporary arrays in expressions when possible.
  6. Provide more convenient use of index arrays (put and take).
A new implementation was decided upon since many of the existing Numeric developers agree that the existing implementation is not suitable for massive changes and enhancements.

This version has nearly the full functionality of the basic Numeric (only masked arrays and the convolve function are missing, and the use of the ufunc methods reduce, accumulate, and outer for complex types). No other libraries have been adapted to Numarray yet. In particular, the FFT and lapack modules are not yet available. Numarray is not fully compatible with Numeric. (But it is very similar in most respects).

The incompatibilities are listed below. The C interface is completely different, so existing C extensions will not work with numarray.

  1. Coercion rules are different. Expressions involving scalars may not produce the same type of arrays.
  2. Types are represented by Type Objects rather than character codes (though the old character codes may still be used as arguments to the functions).
  3. For versions of Python prior to 2.2, arrays have no public attributes. Accessor functions must be used instead (e.g., to get shape for array x, one must use x.getshape() instead of x.shape). When using Python 2.2 or later, however, the attributes of Numarray are in fact available.
A further comment on type is appropriate here. In numarray, types are represented by type objects and not character codes. As with Numeric there is a module variable Float32, but now it represents an instance of a FloatingType class. For example, if x is a Float32 array, x.type() will return a FloatingType instance associated with 32-bit floats (instead of using x.typecode() as is done in Numeric). So the following will not work in numarray:
>>> if x.typecode() == 'f':
rather, use:
>>> if x.type() == Float32:
(All examples presume ``from numarray import *'' has been used instead of ``import numarray'', see section 2.3.1.) The advantage of the new scheme is that other kinds of tests become simpler. The type classes are hierarchical so one can easily test to see if the array is an integer array. For example:
>>> if isinstance(x.type(), IntegralType):
or:
>>> if isinstance(x.type(), UnsignedIntegralType):

Send comments to the NumArray community.