numpy.sum and generator expressions
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... Thanks Neilen -- you know its kind of tragic we live in the new world but we've lost the magic -- Battery 9 (www.battery9.co.za)
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
On Mon, 28 Aug 2006 14:01:59 -0600, Travis Oliphant wrote:
Neilen Marais wrote:
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.
Great, thanks for the fix. Regards Neilen
-Travis
-- you know its kind of tragic we live in the new world but we've lost the magic -- Battery 9 (www.battery9.co.za)
participants (2)
-
Neilen Marais -
Travis Oliphant