[Numpy-discussion] Thoughts about zero dimensional arrays vs Python scalars
Colin J. Williams
cjw at sympatico.ca
Sun Mar 20 11:05:25 EST 2005
Ralf Juengling wrote:
>> It looks as though a decision has been made. I was among those who
>> favoured abandoning rank-0 arrays, we lost.
>> To my mind rank-0 arrays add complexity for little benefit and make
>> explanation more difficult.
> What the current PEP describes is perhaps close to what you want,
> though: It says that indexing an array never results in a zero
> dimensional array but it results "Array Scalars", which are basically
> Python scalars, but there are just more of them to support variety
> the numeric types.
> You could still create zero dimensional arrays by reshaping single
> element arrays though.
>> I don't spot any discussion in the PEP of the pros and cons of the nd
>> == 0 case.
> I don't remember your idea--getting rid of zero dimensional arrays
> altogether--being voiced and discussed on this list. What would be
> the bad consequences of getting rid of zero dimensional arrays?
The argument made in the PEP against returning Python scalars is:
Cons: It is difficult to write generic code because scalars
do not have the same methods and attributes as arrays.
(such as .type or .shape). Also Python scalars have
different numeric behavior as well.
This results in a special-case checking that is not
pleasant. Fundamentally it lets the user believe that
somehow multidimensional homoegeneous arrays
are something like Python lists (which except for
Object arrays they are not).
I suggest that, in striking the balance between the developer or generic
writer and the end user,
the greater design consideration should go to the ease and convenience
of the end user.
More information about the NumPy-Discussion