[Numpy-discussion] rank-0 arrays

Travis Oliphant oliphant at ee.byu.edu
Fri Sep 13 15:53:03 CDT 2002


> Hi Travis,
>
> refresh my memory about how this proposal would work. I've heard
> proposals to add new types to Python itself, but that seems out of
> the question. Are you talking about adding new scalar types as
> module? E.g.
>
> >>> x = Int8(22)
> >>> arr = arange(10, typecode = Int8)
> >>> arr[2]
> Int8(2)
>
> Or some other approach?

This is the gist of it.  Basically you extend the Python scalars to
include the single precision types (all the types Numeric supports).

Ultimately, in Python it would be nice if all of the scalars had the same
base class.

>
> In any case, doesn't this still have the problem that Eric complained
> about, having to test for whether a result is an array or a scalar
> (which was one of the drivers to produce rank-0 results).

I would have to understand his reason better.  He could be right.  My
reason for rank-0 results as always been more of a type issue.  I'll have
to ask him.

Now I remmber an issue that makes me question the proposal:

Currently the length of a rank-0 array is 1, while the length of a scalar
raises an error --- this is a bad difference.

We could still implement rank-0 arrays as a separate (optimized) type
though (so it doesn't carry around the extra baggage of full-rank arrays).

Now-wanting-rank-0-arrays-all-the-time,

-Travis






More information about the Numpy-discussion mailing list