# [PYTHON MATRIX-SIG] returning scalars or rank-0 arrays..

**David Ascher
**
da@maigret.cog.brown.edu

*Tue, 20 Feb 1996 11:34:36 -0500 (EST)*

I'm working on a 'literate' array class, which labels axes and indices.
The point is that one can do slicing based on keyword references to the
axes, and labels for index values. I'll of course make it available
when it's ready for testing.
One issue I've come accross is the "what do I return, a rank-0 entity or
a scalar?". My understanding of the current scheme is that indexing
returns scalars, while slicing returns ranked entities, even if that
rank is 0. Is that correct?
>>>* a = arange(9).reshape(3,3)
*>>>* b = UserArray(a)
*>>>* b
*UserArray([[0,1,2],[3,4,5],[6,7,8]], 'l')
>>>* b[0]
*UserArray([0,1,2], 'l')
>>>* b[0,2]
*2
>>>* b[0,2:3]
*UserArray([2], 'l')
If that's correct, then I guess that's what subclasses of UserArray
should do, although it's not exactly intuitive. Also, should there be
an _as_scalar method in UserArray which returns a scalar in the cases
where self.array is rank-0?
-david
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================