title: subclass ndarray in python numpy: change size and value of array
body: <p>Someone asks the question here: <a href="https://stackoverflow.com/questions/5149269/subclassing-numpy-ndarray-problem">Subclassing numpy ndarray problem</a> but it is basically unanswered.</p>
  
  <p>Here is my version of the question. Suppose you subclass the numpy.ndarray to something that automatically expands when you try to set an element beyond the current shape. You would need to override the <strong>setitem</strong> and use some numpy.concatenate calls to construct a new array and then assign it to "self" somehow. How to assign the array to "self"? </p>
  
  <pre><code>class myArray(numpy.ndarray):
      def __new__(cls, input_array):
          obj = numpy.asarray(input_array).view(cls)
          return(obj)
  
      def __array_finalize__(self, obj):
          if obj is None: return
  
      try:
          super(myArray, self).__setitem__(coords, value)
      except IndexError as e:
          logging.error("Adjusting array")
          ...
          self = new_array # THIS IS WRONG
  </code></pre>