[Numpy-discussion] Poll on a Rank-0 arrays: please give +1, -1, or 0

konrad.hinsen at laposte.net konrad.hinsen at laposte.net
Sat Feb 19 15:03:09 EST 2005

On 19.02.2005, at 22:45, Travis Oliphant wrote:

> 1)  Rank-0 arrays are always returned from uarray operations, Python 
> scalars available on request only.   (*If* arrayobject get's into 
> Python core, Guido has agreed to let rank-0 integer arrays be used as
> index variables).  Rank-0 arrays are made to resmbe scalar of


I consider this a kludge that might be acceptable if no other solution 
is politically doable, but not a desirable feature.

> 2) Rank-0 arrays are never returned from uarray operations (unless 
> using asarray on a scalar), and when a rank-0 array naturally appears 
> in the calculation, an appropriate Python scalar is returned (note 
> that this would lose precision for long doubles unless a new Python 
> object was created).


provided that
1) a special long double type is created
2) the type promotion rules handle scalars in some reasonable way

> 3) The current compromise is continued and for some types a Python 
> scalar is returned, while for other types a  rank-0 array is returned


It works well enough in practice.

> 4) Rank-0 arrays are made equivalent to Python scalars and a new 
> Python scalar for each fundamental data type supported by uarray is 
> constructed (rank-0 arrays would still probably be used internally, 
> but users would not have to know this).   The new Python-scalars would 
> inherit from an existing Python scalar where appropriate and would 
> have the same attributes and methods of uarrays (very likely at least 
> initially they would be seemlessly converted to rank-0 arrays when 
> "mixed" operations occur).


This is still my first choice.


More information about the NumPy-Discussion mailing list