[Numpy-discussion] Questions about converting to numpy
Robert Kern
robert.kern@gmail....
Wed Apr 25 16:31:50 CDT 2007
Christopher Barker wrote:
> I can only help with one:
>> - Even after reading the book I'm not really clear on why one would use
>> numpy.float_ instead of numpy.float or float
>
> They float and numpy.float are the same, and numpy.float_ is the same as
> numpy.float64:
>
> >>> import numpy
> >>> float is numpy.float
> True
> >>> numpy.float64 is numpy.float64
> True
> >>>
>
> float was added to the numpy namespace so that we could write consistent
> code like:
>
> a = array(object, numpy.float32)
> b = array(object, numpy.float)
>
> i.e. have it all in the same namespace.
>
> I'm not sure why float_ is an alias for float64, though I'm guessing
> it's possible that on some platforms they are not the same.
Rather, numpy.float used to be an alias for numpy.float64; however, it overrode
the builtin float() when "from numpy import *" was used at the interactive
prompt. Consequently, we renamed it numpy.float_ and specifically imported the
builtin float as numpy.float such that we didn't break code that had already
started using "numpy.float".
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion
mailing list