[Numpy-discussion] Why the upcasting?

Benyang Tang btang at pacific.jpl.nasa.gov
Wed Jun 12 09:35:05 EDT 2002


The sum of an Int32 array and a Float32 array is a Float64 array, as shown by the following code:

a = Numeric.array([1,2,3,4],'i')
a.typecode(), a.itemsize()

b = Numeric.array([1,2,3,4],'f')
b.typecode(), b.itemsize()

c=a+b
c.typecode(), c.itemsize()

>>> a = Numeric.array([1,2,3,4],'i')
>>> a.typecode(), a.itemsize()
('i', 4)
>>> 
>>> b = Numeric.array([1,2,3,4],'f')
>>> b.typecode(), b.itemsize()
('f', 4)
>>> c=a+b
>>> c.typecode(), c.itemsize()
('d', 8)


Why is the upcasting?

I am using Linux/Pentium/python2.1/numpy20 .

Thanks.

Benyang Tang




More information about the NumPy-Discussion mailing list