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

Untitled

By: a guest on Jun 11th, 2012  |  syntax: None  |  size: 0.49 KB  |  hits: 10  |  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. class ArrayBundle(object):
  2.     def __init__(self, *arrays):
  3.         self._arrays = arrays
  4.     def __getattr__(self, attr):
  5.         def adapter(*args, **kwargs):
  6.             results = [getattr(e, attr)(e, *args, **kwargs) for e in self._arrays]
  7.             return ArrayBundle(*results)
  8.         return adapter
  9.     def __repr__(self):
  10.         return "ArrayBundle%r" % (self._arrays)
  11.  
  12. import numpy as num
  13.  
  14. x = num.random.randn(4,3)
  15. y = num.random.randn(2,2)
  16.  
  17. q = ArrayBundle(x,y)
  18. print q.sum()