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

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. Colin W.

Colin J. Williams wrote:
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.
How are you defining "end user"? To my definition, an end user will neither know nor care whether rank-0 arrays or Python ints, longs, floats, or complexes are returned. They will be at a GUI seeing graphs or reading output. They won't see a bit of code. The "generic code" being talked about in the PEP isn't code inside Numeric itself. It's all of the stuff written *using* Numeric. Now, if you are defining "end user" to be the people using Numeric to write code, then we can argue about which choice is simpler or more convenient. There are some situations in which the rank-0 approach is more convenient and some in which the Python scalar is preferred. I'm not sure that we can reliably enumerate them. I would suggest that Option 2, returning Python types when the typecode allows and rank-0 arrays otherwise, is an inconsistency that we could do without. -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
participants (2)
-
Colin J. Williams
-
Robert Kern