[Numeric] why is Float32 incorrect for ufuncs?

Duncan Smith buzzard at urubu.freeserve.co.uk
Thu Mar 4 14:38:57 EST 2004


"Curzio Basso" <curzio.basso at unibas.ch> wrote in message
news:404757b9$1 at maser.urz.unibas.ch...
> Hello everyone,
>
> I am a beginner with Numerical Python, and there is a thing I do not
> understand in the behaviour of the ufuncs. Maybe someone can enlighten me.
>
> Why is the following not working?
>
>  >>> import Numeric
>  >>> a=Numeric.ones((2,2),Numeric.Float32)
>  >>> a
> array([[ 1.,  1.],
>         [ 1.,  1.]],'f')
>  >>> a/=2
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
> TypeError: return array has incorrect type
>
> If I use Numeric.Float64 as typecode everything works fine, but I do not
> understand why is this needed.
>
> thanks for your help. curzio.
>

What *I think* is happening is that Numeric is converting the integer to a
rank-0 array of type Int64 before division.  The consequence is an upcast to
Float64 for the return array.  Look for 'Coercion and Casting' in the
Numeric documentation.  Cheers.

Duncan





More information about the Python-list mailing list