title: How do I make existing functions in math and numpy module support user-defined objects?
body: <p>I defined a class that I'd like basic operations such as <code>+</code>, <code>-</code>, and even more advanced math operations such as <code>sin</code> to support. That is, I need to define some new rules for these basic operators and math functions.</p>
  
  <p>I could deal with basic operators using Python's magic methods as below,</p>
  
  <pre><code>class NewObj():
  
      def __init__(self, *args):
          pass
  
      def __add__(self, other):
          pass
  
      def __mul__(self, other):
          pass
  
      # Use magic methods to define other basic operators below...
  </code></pre>
  
  <p>And I could also redefine basic functions in the same .py file where class <code>NewObj</code> is defined, such as</p>
  
  <pre><code>def sin(x):
      pass
  </code></pre>
  
  <p>And name this file as, say, myoperator.py. Then I could import this module and apply new operations on <code>NewObj</code> objects.  </p>
  
  <hr>
  
  <p>But I also want existing functions in <code>numpy</code> and <code>math</code> to support my <code>NewObj</code> objects so that <code>math.sin()</code> and <code>numpy.sin()</code> also support my newly defined <code>NewObj</code> objects. How can I achieve this?</p>
  
  <p>Another question is: is it possible to encapsulate functions inside my <code>NewObj</code> class just like magic methods so that all the stuff are written inside a class data structure?</p>