title: Avoid repetitive big arrays computation inside a function in Python
body: <p>I call repetitively - during a minimisation process - a function that requires big arrays. Here is a dummy example</p>
  
  <pre><code>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
  </code></pre>
  
  <p>During the minimisation process, the array size <code>N</code> doesn't change, so I would like to use the same array to avoid useless computation and memory allocation.</p>
  
  <p>Also I would like the function <code>foo</code> to be self-consistent, meaning that I don't want another function to create the array and give it to <code>foo</code> during the minimisation process.</p>
  
  <p>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?</p>