This is a simplification of my question. I have a numpy array:
x = np.array([0,1,2,3])
and I have a function:
def f(y): return y**2
I can calculate f (x).
Now suppose I really want to compute f (x) for repeated x:
x = np.array([0,1,2,3,0,1,2,3,0,1,2,3])
Is there a way to do this without creating a duplicate version of x and in a way transparent to f?
In my particular case, f is the function involved, and one of the arguments is x. I would like to be able to calculate f when x repeats without repeating it, since it does not fit in memory.
Overwriting f to handle duplicate x would work, and I was hoping for a smart way, perhaps to subclass the numpy array for this.
Any advice appreciated.
source
share