Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 14th, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. numpy: point sum
  2. >>> from pandac.PandaModules import Vec3
  3. >>> import numpy
  4. >>> l = []
  5. >>> l.append( Vec3(1,1,1) )
  6. >>> l.append( Vec3(1,1,1) )
  7. >>> l.append( Vec3(1,1,1) )
  8. >>> Vec3(1,1,1)+Vec3(1,1,1)
  9. Vec3(2, 2, 2)
  10. >>> sum(l)
  11. Traceback (most recent call last):
  12.   File "<stdin>", line 1, in <module>
  13. TypeError: unsupported operand type(s) for +: 'int' and 'libpanda.Vec3'
  14. >>> numpy.sum(l)
  15. 9.0
  16. >>>
  17.        
  18. >>> my_smart_sum(l)
  19. Vec3(3,3,3)
  20.        
  21. sum(l, start=Vec3(0,0,0))
  22.        
  23. numpy.sum(l, axis=0)
  24.        
  25. python -m timeit "import numpy; foo = [[1,1,1],[1,1,1]]" "numpy.sum(foo, axis=0)"
  26. 10000 loops, best of 3: 46.5 usec per loop