>>> from pandac.PandaModules import Vec3
>>> import numpy
>>> l = []
>>> l.append(Vec3(1,1,1))
>>> l.append(Vec3(1,1,1))
>>> l.append(Vec3(1,1,1))
>>> Vec3(1,1,1)+Vec3(1,1,1)
Vec3(2, 2, 2)
>>> sum(l)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'libpanda.Vec3'
>>> numpy.sum(l)
9.0
>>>
我想要一些快(快==不是纯Python但numpy的速度环)方法才达到:numpy的:点之
>>> my_smart_sum(l)
Vec3(3,3,3)
好的我发现这个方法:reduce(lambda x,y:x + y,l)有一些缺点吗? – nkint 2011-12-17 17:36:48
有一个缺点,它是最好的解释[这里](http://stackoverflow.com/questions/1892324/why-program-functionally-in-python/1892614#1892614)。 – 2011-12-17 18:22:59