[SciPy-user] numpy.sum and generator expressions
Travis Oliphant
oliphant.travis at ieee.org
Mon Aug 28 15:01:59 CDT 2006
Neilen Marais wrote:
> Hi
>
> I have a lot of code that uses numpy.sum with generator expressions:
>
> import numpy as N
>
> a = sum(i for i in xrange(3))
>
> Of course the generator expressions are a little more involved than that.
> With numpy 0.9.8 this works as expected:
>
> In [1]: import numpy as N
> In [2]: N.sum(i for i in range(3))
> Out[2]: 3
>
> but with 1.0b4 I get:
>
> In [14]: N.sum(i for i in range(3))
> Out[14]: <generator object at 0x2aaaae5e3248>
>
> Is this the (new?) expected bahaviour, or is it a bug? I hope for the
> latter, since I use generators like this quite a bit...
>
It's a bug. It was introduced when adding an optional output argument
to sum. In the sum function in fromnumeric.py there needs to be a
return res statement in the check for a generator type.
This is fixed in SVN.
-Travis
More information about the SciPy-user
mailing list