[Numpy-discussion] Thoughts about zero dimensional arrays vs Python scalars

Travis Oliphant oliphant at ee.byu.edu
Sun Mar 20 22:28:42 EST 2005

Colin J. Williams wrote:

> It looks as though a decision has been made.  I was among those who 
> favoured abandoning rank-0 arrays, we lost.
I don't understand how you can say this.  In what way have rank-0 arrays 
not been abandoned for the new Array Scalar objects?   By the way, these 
array scalar objects can easily be explained as equivalent to the type 
hierarchy of current numarray (it is essentially identical --- it's just 
in C).

> To my mind rank-0 arrays add complexity for little benefit and make 
> explanation more difficult.

I don't know what you mean.  rank-0 arrays are built into the 
arrayobject type.  Removing them is actually difficult.   The easiest 
thing to do is to return rank-0 arrays whenever the operation allows 
it.  It is the confusion with desiring to use items in an array (which 
are logically rank-0 arrays) as equivalent to Python scalars that 
requires the Array Scalars that "bridge the gap" between rank-0 arrays 
and "regular" Python scalars.

Perhaps you mean that "Array Scalars" add complexity for "little 
beneift" and not "rank-0 arrays".  To address that question:   It may 
add complexity, but it does add benefit (future optimization, array type 
hierarchy, and a better bridge between the problem of current Python 
scalars and array-conscious scalars).  This rank-0 problem has been a 
wart with Numeric for a long time.  Most of us long-time users work 
around it, but heavy users are definitely aware of the problem and a bit 
annoyed.   I think we have finally found a reasonable "compromise" 
solution in the Array Scalars.  Yes, it did take more work to implement 
(and will take a little more work to maintain --- you need to add 
methods to the GenericScalar class when you add them to the Array 
Class), but I can actually see it working. 


More information about the NumPy-Discussion mailing list