title: How can I create my own datatype in python so that I could overwrite arithmetic operators?
body: <p>I am currently using Python/Numpy to deal with geographical/GPS data (loving it!), and I am facing the recurring task to calculate distances between geographical points defined by a coordinate pair <code>pn = [lon, lat]</code>.</p>
  
  <p>I have a function that I use like this: <code>dist = geodistance(p1, p2)</code> which is analog to euclidean distance in linear algebra (vector subtraction/difference), but occurs in geodesical (spherical) space instead of rectangular euclidean space.</p>
  
  <p>Programmatically, euclidean distance is given by</p>
  
  <pre><code>dist = ((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)**0.5
  </code></pre>
  
  <p>Mathematically, this is equivalent to the "idiomatic" (for lack of a better word) sentence </p>
  
  <pre><code>dist = p1 - p1   # the "norm" of the vector difference, subtraction.
  </code></pre>
  
  <p>Currently, I get my distance like this:</p>
  
  <pre><code>p1 = [-51.598354,-29.953363]
  p2 = [-51.598701,-29.953045]
  dist = geodistance(p1, p2)
  print dist
  
  &gt;&gt; 44.3904032407
  </code></pre>
  
  <p>I would like to do this:</p>
  
  <pre><code>print p2 - p1  # these points now are from some fancy datatype
  
  &gt;&gt; 44.3904032407
  </code></pre>
  
  <p>And the final goal:</p>
  
  <pre><code>track = numpy.array([[-51.203018 -29.996149]
                       [-51.203018 -29.99625 ]
                       [-51.20266  -29.996229]
                       [-51.20229  -29.996309]
                       [-51.201519 -29.99416 ]], dtype=fancy)  # (**) or something like
  
  print numpy.diff(track)
  
  &gt;&gt; ndarray([[   0.        ]
              [   7.03531252]
              [  39.82663316]
              [  41.50958596]
              [ 172.49825765]])
  </code></pre>
  
  <p>A similar thing is: if you take two <code>datetime</code> objects and subtract them, the operation returns a <code>timedelta</code> object. I want to subtract two coordinates and get a geodesic distance as the result.</p>
  
  <p>I wonder if a class would work, but dtype (a "subtype" of float32, for example) would help a lot upon array creation from lists (** which is how I read things from xml files).</p>
  
  <p>Thanks a lot!</p>