numarray provides limited support for dimensionless arrays which represent
single values, also known as rank-0 arrays. Rank-0 arrays are the array
representation of a scalar value. They have the advantage over scalars that
they include array specific type information, e.g. Int16. Rank-0 arrays
can be created as follows:
>>> a = array(1); a
array(1)
A rank-0 array has a 0-length or empty shape:
>>> a.shape
()
numarray's rank-0 array handling differs from that of Numeric in two ways.
First, numarray's rank-0 arrays cannot be indexed by 0:
>>> array(1)[0]
Traceback (most recent call last):
...
IndexError: Too many indices
Second, numarray's rank-0 arrays do not have a length.
>>> len(array(1))
Traceback (most recent call last):
...
ValueError: Rank-0 array has no length.
Finally, numarray's rank-0 arrays can be converted to a Python scalar by
subscripting with an empty tuple as follows: