[SciPy-Dev] Possibly a bug in scipy.spatial.distance.mahalanobis

Warren Weckesser warren.weckesser at gmail.com
Mon Dec 29 09:27:46 EST 2014


On Mon, Dec 29, 2014 at 6:53 AM, Simen Langseth <simlangen at gmail.com> wrote:

> Dear Scipy Developers:
>
> The documentation below mentions the following for the formula of
> mahalanobis distance:
>
> [image: \sqrt{ (u-v) V^{-1} (u-v)^T }]
>
>
> http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.distance.mahalanobis.html#scipy.spatial.distance.mahalanobis
>
> However, in the following source code, the transpose of the delta seems to
> be missing.
>
> u = _validate_vector(u) v = _validate_vector(v)VI = np.atleast_2d(VI)delta
> = u - vm = np.dot(np.dot(delta, VI), delta)return np.sqrt(m)
>
>
>
>
> https://github.com/scipy/scipy/blob/6a7327e8bb8248b2ea165180bc602edf1ab33dda/scipy/spatial/distance.py
>
> Please forgive me if I could not understand the source code perfectly.
>
>

The x and y arguments to mahalanobis() must be one-dimensional arrays.
This is enforced by _validate_vector(), which converts arguments with shape
(N,1) or (1,N) to have shape (N,).  A transpose applied to a
one-dimensional array doesn't do anything, so there is no need for the
transpose operation in the code.

Warren


Thanks.
>
> Simen
>
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20141229/7d9b667d/attachment.html>


More information about the SciPy-Dev mailing list