[Numpy-discussion] Accessing rank-0 array value?

Todd Miller jmiller at stsci.edu
Mon Jun 7 06:47:01 CDT 2004


On Mon, 2004-06-07 at 06:50, Nadav Horesh wrote:
> b has a scalar properties:
> 
> >>> b+3
> 5
> 
> >>> b.rank
> 0
> 
> The odd issue is that rank>0 arrays keeps their type in similar operations:
> 
> >>> a = array((2,), type=Int16)
> >>> a
> array([2], type=Int16)
> 
> >>> a + 3
> array([5], type=Int16)
> 
> I would expect that rank 0 arrays would behave like scalars with a given numarray type (Int8, UInt64, ...).
> 
>   Nadav.

Originally, I think your expected behavior was the behavior.  The
official policy now, always subject to debate, is that rank-0 arrays
should be a mostly hidden implementation detail.  The fact that a scalar
is returned here is a matter of consistency and no accident.  (This is
not to say that I'm confident that we're completely consistent... I'm
just trying to explain the direction we're heading.)

Todd

-- 
Todd Miller <jmiller at stsci.edu>





More information about the Numpy-discussion mailing list