[Numpy-discussion] rank-0 arrays

Travis Oliphant oliphant at ee.byu.edu
Fri Sep 13 13:00:07 CDT 2002

> Two other issues come up trying to implement the "rank-0 experiment":
> 1.  What should be the behavior of subscripting a rank-0 array?
> a.  Return the scalar value                         (what numarray does
> now.  seems inconsistent)

> b.  Raise an exception

> c.  Return a copy  of the rank-0 array

> 2.  What's a decent notation for .asScalar()?
> a.  a[ <subscript_resulting_in_rank0> ][0]                (what numarray
> does now)

Numeric does this now for backward compatibility.  I don't think this
issue was discussed at length.

> b.  a[ <subscript_resulting_in_rank0> ]()                  (override
> __call__)

> c.  a[ <subscript_resulting_in_rank0> ].asScalar()
+1  just keep the current .toscalar()  notation.

Also int(a) and float(a) and complex(a) would work as well.

If we just implemented Python scalars for the other precisions then much
of this rank 0 array business would be solved as we could always return
the Python scalar rather than an array for rank 0 arrays.

I believe Konrad made this suggestion many moons ago and I would agree
with him.

-Travis Oliphant

More information about the Numpy-discussion mailing list