[SciPy-dev] numpy changes generator behaviour
David M.Cooke
cookedm at physics.mcmaster.ca
Mon Jan 9 10:10:55 CST 2006
On Jan 9, 2006, at 09:01 , Christopher Fonnesbeck wrote:
> I'm not sure this is intended, but it appears that numpy changes
> the behaviour of the new python 2.4 generators. Here is what is
> supposed to happen:
>
> >>> sum(x*x for x in range(10))
> 285
>
> But if I import numpy, and try again I get:
>
> >>> from numpy import *
> >>> sum(x*x for x in range(10))
> <generator object at 0x5ae90>
>
> Why should it no longer sum?
Because the function 'sum' is now the one from numpy, not the builtin
one. (Numeric had 'sum' before it was added to Python.)
You could do something like
bsum = sum
from numpy import *
bsum(x*x for x in range(10))
Or, to get the builtin sum after overwriting it:
import __builtin__
__builtin__.sum(x*x for x in range(10))
--
|>|\/|<
/------------------------------------------------------------------\
|David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca
More information about the Scipy-dev
mailing list