[Numpy-discussion] bad generator behaviour with sum

listservs at mac.com listservs at mac.com
Sun Aug 27 17:09:32 CDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Aug 27, 2006, at 4:19 PM, numpy-discussion- 
request at lists.sourceforge.net wrote:

>>
>> It seems like numpy.sum breaks generator expressions:
>>
>> In [1]: sum(i*i for i in range(10))
>> Out[1]: 285
>>
>> In [2]: from numpy import sum
>>
>> In [3]: sum(i*i for i in range(10))
>> Out[3]: <generator object at 0x10eca58>
>>
>> Is this intentional? If so, how do I get the behaviour that I am  
>> after?
>>
>
>
> In [3]: sum([i*i for i in range(10)])
> Out[3]: 285

Well, thats a list comprehension, not a generator expression. I was  
after the latter because it is more efficient.

Thanks,
C.

- --
Christopher Fonnesbeck
+ Atlanta, GA
+ fonnesbeck at mac.com
+ Contact me on AOL IM using email address


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFE8hgdkeka2iCbE4wRAq8lAJ9dKPYQ35IE3qacf9K1KsBL59mdRACePn5S
x0wHWs/PrVcJHCqf9tbQwRk=
=0wFp
-----END PGP SIGNATURE-----




More information about the Numpy-discussion mailing list