[Numpy-discussion] Poll on a Rank-0 arrays: please give +1, -1, or 0
perry at stsci.edu
Sun Feb 20 07:58:32 CST 2005
I'm going to refrain from a numerical rating but rather add a few comments
> 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
A minor question, in this and other cases where rank-0 is being used, what
will repr show? For example, if I do:
>>> x = arange(2)
do I get '0' or 'array(0)' ?
I suppose the former is fine if rank-0 is usable in every way as a scalar
and no one really needs to know the difference, but I troubles me a bit to
hide this fact (with repr) if it isn't quite the same.
Along those lines (for this case and the last) I worry that there are
potential gotchas that haven't been discovered yet. How confident are you
that there aren't any in trying to integrate rank-0 with Python scalars and
their usage. It may be one of those things that is hard to know unless the
work of trying to implement it is actually done. You've thought about this a
lot more than I have.
> 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
As Konrad mentions, as long as there is some means of handling long doubles,
I find scalars perfectly acceptable. I tend to think that is what most user
assume they are getting.
> 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
I've never really liked this behavior.
> 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
Sounds good if there are no gotchas but may be a lot of work (coding and
political). Any performance issues regarding rank-0 vs scalars? Will users
pay a penalty for using rank-0 in scalar-like expressions (no apparent array
usage other than the rank-0 values)?
More information about the Numpy-discussion