title: Python - How to wrap the np.ndarray class?
body: <p>I'm trying to add a functionality to the np.ndarray class.</p>
  
  <p>I was hoping it would be as simple as the following:</p>
  
  <pre><code>class myArray(np.ndarray):
  
      def __init__(self, *args, **kwargs):
          self = np.array(*args, **kwargs)
          # super(ImArray, self).__init__(*args, **kwargs) &lt;-- my first attempt didn't work
          if self.ndim == 4:
              self.myShape = (self.shape[0]*self.shape[1], self.shape[2]*self.shape[3])
          else:
              self.myShape = self.shape
  
      def myStuff(self):
          self = self.reshape(self.myShape)
  
  a = np.zeros([2, 2, 2, 2])
  myArray(a)
  # TypeError: only length-1 arrays can be converted to Python scalars
  a = range(10)
  myArray(a)
  # AttributeError: 'numpy.ndarray' object has no attribute 'myShape'
  </code></pre>
  
  <p>Please let me know if you want more information or something similar.</p>
  
  <p>EDIT:</p>
  
  <p>To give a bit more information abuot why I want to do this, as someone suggested simply making a function might be more appropriate.</p>
  
  <p>I want to add the following:</p>
  
  <pre><code>A.newFun(B)
  </code></pre>
  
  <p>which would be the same as:</p>
  
  <pre><code>def newFun(A,B):
      oldShapeA = A.shape
      A = np.matrix( A.reshape([A.shape[0]*A.shape[1], A.shape[2]*A.shape[3]]) )
      oldShapeB = B.shape
      B = np.matrix( B.reshape([1, -1]) )
      out = A*B
      out = np.reshape(out.A, oldShapeA[:2]+oldShapeB)
      return out
  </code></pre>
  
  <p>I have left out a lot of checks such as that the dimenions are correct etc but hopefully you get the point</p>