numarray
, like Numeric
, has support for arrays of character data
(provided by the numarray.strings
module) in addition to arrays of
numbers. The support for character arrays in Numeric
is relatively
limited, restricted to arrays of single characters. In contrast,
numarray
supports arrays of fixed length strings. As an additional
enhancement, the numarray
design supports interleaving arrays of
characters with arrays of numbers, with both occupying the same memory buffer.
This provides basic infrastructure for building the arrays of heterogenous
records as provided by numarray.records
(see chapter
12). Currently, neither Numeric
nor numarray
provides support for unicode.
Each character array is a CharArray
object in the
numarray.strings
module. The easiest way to construct a character array
is to use the numarray.strings.array()
function. For example:
>>> import numarray.strings as str >>> s = str.array(['Smith', 'Johnson', 'Williams', 'Miller']) >>> print s ['Smith', 'Johnson', 'Williams', 'Miller'] >>> s.itemsize() 8
The character array is just like an array in numarray, except that now each element is conceptually a Python string rather than a number. We can do the usual indexing and slicing:
>>> print s[0] 'Smith' >>> print s[:2] ['Smith', 'Johnson'] >>> s[:2] = 'changed' >>> print s ['changed', 'changed', 'Williams', 'Miller']
Send comments to the NumArray community.