From: Todd M. <jm...@st...> - 2004-06-07 16:04:41
|
On Mon, 2004-06-07 at 11:51, Colin J. Williams wrote: > Todd, > > What are the objections to returning a scalar? Where? > To me, this seems to be > simpler than some kluge, such as float(array) or int(array). To use > these, one has first to determine what array._type is. I don't think so. What you get is driven by what you ask for, not the type of the array: >>> a = numarray.array(10) >>> float(a) 10.0 >>> int(a) 10 >>> a = numarray.array(10.0) >>> int(a) 10 >>> float(a) 10.0 >>> complex(a) (10+0j) Regards, Todd > Colin W. > > Todd Miller wrote: > > >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 <jm...@st...> |