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

Emmanuel Viennet viennet at lipn.univ-paris13.fr
Fri Jul 20 02:11:31 CDT 2001


 Feature, I think.

a[1,3] is a rank-0 array, with typecode Int16.
There is no other way to handle a Int16 scalar
in Python (Int16 is not a python type).
This solution allows to correctly propagate 
the types in array arithmetic, without unwanted 
upcasts.

Emmanuel

Chris Barker wrote:
> # now change the type
> >>> a = a.astype(Int16)
> >>> a.shape = (10,)
> >>> print type(a[3])
> <type 'int'>
> #it's an Int
> 
> >>> a.shape = (2,5)
> # now change the shape to rank-2
> 
> >>> print type(a[1,3])
> <type 'array'>
> 

>>> print a[0,0].typecode()
's' # == Int16
>>> a[0,0].shape   
() # rank-0 array




More information about the Numpy-discussion mailing list