[Numpy-discussion] typecasting of single values form an array: Bug or feature?

Chris Barker chrishbarker at home.net
Fri Jul 20 14:48:22 EDT 2001


Konrad Hinsen wrote:
> 
> >  Feature, I think.
> 
> Right, but a relatively recent one. In the first NumPy releases, the
> result was a scalar Integer object. There are good arguments for both
> variants.

OK. I see that there are trade-offs either way, and I certainly see the
benefit of keeping the precision consistent(even though it would be
easier in this case to have th upcast).

I do think it's a bug, however, to have the upcast when pulling a single
value out of a 1-d array, but not when pulling it out of a higher rank
array:

>>> a = array(((1,2,3),(4,5,6)),Int16)

>>> type(a[1,1])
<type 'array'>

>>> a.shape = (6,)

>>> type(a[2])
<type 'int'>

>>>

This seems totally inconsistant. Note that this same effect occurs for
arrays of type Float16 (and probably others)

By the way, would it be at all possible for Python to accept an array of
rank 0 as an index? How big a change would that be?

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------




More information about the NumPy-Discussion mailing list