Questions about converting to numpy
So I finally bit the bullet and converted most of my code from Numeric and numarray to numpy. (I haven't yet tried to convert one package that makes heavy use of nd_image and has C extensions).
But it left me with a few questions:
 What exception does numpy throw if it runs out of memory? (I can try harder to make it do that, but trying to chew up all memory tends to slow the machine down and my first tests weren't successful)  the equivalent to numarray.memory.error. The numpy book is silent on the issue of what exceptions numpy can throw (at least the index was).
 Is there a list of the data types that we can expect to be available on all regular platforms (including 32bit linux, MacOS X and Windows) and of usual speed for computations (instead of some kind of slow emulation)?
 Even after reading the book I'm not really clear on why one would use numpy.float_ instead of numpy.float or float for daytoday programming (where the size doesn't matter enough to use float64 or whatever). Any hints?
Overall it went fine. I'm not entirely sure I caught everything yet, but the new code seems to be working.
 Russell
Russell E. Owen wrote:
So I finally bit the bullet and converted most of my code from Numeric and numarray to numpy. (I haven't yet tried to convert one package that makes heavy use of nd_image and has C extensions).
But it left me with a few questions:
 What exception does numpy throw if it runs out of memory? (I can try
harder to make it do that, but trying to chew up all memory tends to slow the machine down and my first tests weren't successful)  the equivalent to numarray.memory.error. The numpy book is silent on the issue of what exceptions numpy can throw (at least the index was).
The standard MemoryError exception.
 Is there a list of the data types that we can expect to be available
on all regular platforms (including 32bit linux, MacOS X and Windows) and of usual speed for computations (instead of some kind of slow emulation)?
Not anywhere particular, but these might not be available/useful on all platforms: float96, float128, float256, complex182, complex256, complex512, int64, uint64, int128, uint128, longlong, ulonglong, longfloat, clongfloat.
 Even after reading the book I'm not really clear on why one would use
numpy.float_ instead of numpy.float or float for daytoday programming (where the size doesn't matter enough to use float64 or whatever). Any hints?
If you wanted an array scalar of the "default" float dtype (whatever that happened to be), you would have to use float_. Of course the "default" float dtype is always (and will always be, AFAICT) float64, so really, you might as well use that.
Russell E. Owen wrote:
So I finally bit the bullet and converted most of my code from Numeric and numarray to numpy.
good for you!
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.
Chris
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".
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
Russell E. Owen wrote:
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.
For specifying dtype=float in functions that take such an argument, go ahead and use dtype=float. There isn't really a reason to use anything else if you don't want to. However, the scalar type objects are used in other places, so float_ should exist.
participants (3)

Christopher Barker

Robert Kern

Russell E. Owen