[Numpy-discussion] Questions about converting to numpy

Russell E. Owen rowen@cesmail....
Thu Apr 26 13:50:39 CDT 2007


In article <462FC8C6.3030200@gmail.com>,
 Robert Kern <robert.kern@gmail.com> wrote:

> 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".

But I still don't understand why one shouldn't just use dtype=float or 
numpy.float. Does that result in an array with a different type of float 
than numpy.float_ (float64)? Or does it just somehow speed up numpy 
because it doesn't have to convert the python type into a numpy dtype.

Anyway, thank you all for the helpful answers! I'm glad numpy throws the 
standard MemoryError since I'm already testing for that.

-- Russell



More information about the Numpy-discussion mailing list