I call repetitively - during a minimisation process - a function that requires big arrays. Here is a dummy example
def foo(N,a):
big_array = np.mgrid[0:N,0:N]
b = np.fft.fft2(big_array[0]**a) #some heavy computation
return b
During the minimisation process, the array size N doesn't change, so I would like to use the same array to avoid useless computation and memory allocation.
Also I would like the function foo to be self-consistent, meaning that I don't want another function to create the array and give it to foo during the minimisation process.
Given these requirements, I was thinking to use a callable object with the array as an attribute. What do you think about this? Is there a more pythonic way to do?
big_array = np.mgrid[0:N,0:N]. The goal is to make the program faster