[Numpy-discussion] rank-0 arrays
xscottg at yahoo.com
Fri Sep 13 10:17:09 CDT 2002
--- Todd Miller <jmiller at stsci.edu> wrote:
> 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)
If you think of it as "dereferencing" instead of "indexing", I think this
is most consistent. It takes 3 elements to dereference a rank-3 array, so
it should take 0 elements to dereference a rank-0 array.
> 2. What's a decent notation for .asScalar()?
> a. a[ <subscript_resulting_in_rank0> ] (what numarray
> does now)
> b. a[ <subscript_resulting_in_rank0> ]() (override
> c. a[ <subscript_resulting_in_rank0> ].asScalar()
> Any strong opinions?
Since subscripting a rank-3 array:
a[1, 2, 3]
is very much like
a[(1, 2, 3)]
The __getitem__ receives the tuple (1, 2, 3) in both cases. (Try it!)
So that would imply subscripting (dereferencing) a rank-0 array could be:
a could be represented by a[()]
It's just unfortunate that Python doesn't currently recognize the a as a
Do you Yahoo!?
Yahoo! News - Today's headlines
More information about the Numpy-discussion