title: One dimensional Mahalanobis Distance in Python
body: <p>I've been trying to <strong>validate</strong> my code to calculate <strong>Mahalanobis distance</strong> written in <strong>Python</strong> (and double check to compare the result in OpenCV) 
  My data points are of 1 dimension each (5 rows x 1 column). </p>
  
  <p>In <strong>OpenCV (C++)</strong>, I was successful in calculating the Mahalanobis distance when the <strong>dimension</strong> of a data point was with above dimensions.</p>
  
  <p>The following code was <strong>unsuccessful</strong> in calculating Mahalanobis distance when dimension of the matrix was 5 rows x 1 column. <strong>But it works when the number of columns in the matrix are more than 1</strong>:</p>
  
  <pre><code>import numpy;
  import scipy.spatial.distance;
  s = numpy.array([[20],[123],[113],[103],[123]]);
  covar = numpy.cov(s, rowvar=0);
  invcovar = numpy.linalg.inv(covar)
  print scipy.spatial.distance.mahalanobis(s[0],s[1],invcovar);
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/abc/Desktop/Return.py", line 6, in &lt;module&gt;
      invcovar = numpy.linalg.inv(covar)
    File "/usr/lib/python2.6/dist-packages/numpy/linalg/linalg.py", line 355, in inv
      return wrap(solve(a, identity(a.shape[0], dtype=a.dtype)))
  IndexError: tuple index out of range
  </code></pre>