title: Python lazy evaluation numpy ndarray
body: <p>I have a large 2D array that I would like to declare once, and change occasionnaly only <em>some</em> values depending on a parameter, without traversing the whole array. </p>
  
  <p>To build this array, I have subclassed the numpy ndarray class with <code>dtype=object</code> and assign to the elements I want to change a function e.g. :</p>
  
  <pre><code>def f(parameter):
       return parameter**2
  
  for i in range(np.shape(A)[0]):
      A[i,i]=f
      for j in range(np.shape(A)[0]):
          A[i,j]=1.
  </code></pre>
  
  <p>I have then overridden the <code>__getitem__</code> method so that it returns the evaluation of the function with given parameter if it is callable, otherwise return the value itself.</p>
  
  <pre><code>    def __getitem__(self, key):
          value = super(numpy.ndarray, self).__getitem__(key)
          if callable(value):
              return value(*self.args)
          else:
              return value
  </code></pre>
  
  <p>where <code>self.args</code> were previously given to the instance of myclass.</p>
  
  <p>However, I need to work with float arrays at the end, and I can't simply convert this array into a <code>dtype=float</code> array with this technique. I also tried to use numpy views, which does not work either for <code>dtype=object</code>.</p>
  
  <p>Do you have any better alternative ? Should I override the view method rather than getitem ? </p>
  
  <p><strong>Edit</strong> I will maybe have to use Cython in the future, so if you have a solution involving e.g. C pointers, I am interested.</p>