float / double support in Python?

jsaul jsaul at gmx.de
Fri Feb 7 13:10:28 CET 2003


* jsaul [2003-02-07 12:40]:
> * Alex Martelli [2003-02-07 11:21]:
> > What you can do...:
> >
> > >>> a=arange(0, 10, typecode='f')
> > >>> a.savespace(1)
> > >>> a*=1.
> > >>> a
> > array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.],'f')
> > >>>
>
> Oh yes, that's good news. The bad news is, unfortunately:
> >>> a.typecode()
> 'f'
> >>> b = a*2j
> >>> b.typecode()
> 'f'
> >>> b
> array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],'f')

Yet another weird behaviour:

>>> from Numeric import *
>>> a = arange(10,typecode='i')
>>> a.savespace(1)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],'i')
>>> a/2
array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4],'i')
>>> a/2.
array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4],'i')
>>> a*0.5
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0],'i')

I.e. int/float division gives the same result as int/int if the
savespace flag is set. Fine. However, I would expect »a*0.5« to
return the same as »a/2.«, which is not the case.

Cheers, jsaul
-- 
Palo pa'que aprenda que aquí sí hay honor!
[Rubén Blades]




More information about the Python-list mailing list