title: some Numpy functions return ndarray instead of my subclass
body: <p>I am subclassing Numpy's ndarray class, adding some meta-data and additional methods. I'm  trying to follow the instructions in <a href="http://docs.scipy.org/doc/numpy/user/basics.subclassing.html">this article</a> and <a href="http://www.scipy.org/Subclasses">that one</a>. However, some Numpy (or Scipy) functions return the base class "ndarray" instead of my custom subclass. Other Numpy functions DO return my subclass, and I don't know what's the reason for the difference. How can I make all the numpy/scipy functions return my subclass? here's what I did:</p>
  
  <pre><code>class Signal(np.ndarray):
      def __new__(cls, filename):
          #print "In __new__" #TEMP DEBUG
          ret = np.fromfile(filename, dtype = np.int32)
          ret = ret.view(cls) # convert to my class, i.e. Signal
          ret.parse_filename(filename)
          return ret
  
      def __array_finalize__(self, obj):
          #print "in __array_finalize__" #TEMP DEBUG
          if obj is None: return # shouldn't actually happen.
          # copy meta-fields from source, if it has them (otherwise put None's)
          self.filename = getattr(obj, "filename", None)
          self.folder = getattr(obj, "folder", None)
          self.label = getattr(obj, "label", None)
          self.date = getattr(obj, "date", None)
          self.time = getattr(obj, "time", None)
          #etc
  </code></pre>
  
  <p>here are some usage examples: </p>
  
  <p>these work as expected -</p>
  
  <pre><code>&gt;&gt;&gt; s = Signal(filename)
  &gt;&gt;&gt; s2 = s[10:20]
  &gt;&gt;&gt; type (s2)
  &lt;class '__main__.Signal'&gt;
  &gt;&gt;&gt; s3 = s + 17
  &gt;&gt;&gt; type (s3)
  &lt;class '__main__.Signal'&gt;
  &gt;&gt;&gt; s4 = np.sqrt(s)
  &gt;&gt;&gt; type(s4)
  &lt;class '__main__.Signal'&gt;
  </code></pre>
  
  <p>however, what about these?</p>
  
  <pre><code>&gt;&gt;&gt; s5 = log10(s)
  &gt;&gt;&gt; type(s5)
  &lt;type 'numpy.ndarray'&gt;
  &gt;&gt;&gt; s6 = np.fft.fft(s)
  &gt;&gt;&gt; type(s6)
  &lt;type 'numpy.ndarray'&gt;
  </code></pre>
  
  <p>looking into the code of <code>fft</code> and <code>log10</code> I can see that they use <code>asarray()</code>, which strips the subclass and returns an ndarray, explaining the behavior. Therefore, my question isn't "why, technically, this happens" but more a design question - how should I write my code so this doesn't happen?</p>
  
  <p>p.s. I'm a newbie both at Python and here on Stack Overflow, so please excuse any obvious mistakes or inappropriateness...</p>
  
  <p>thanks,
  Guy.</p>