SciPy

scipy.spatial.distance.is_valid_dm

scipy.spatial.distance.is_valid_dm(D, tol=0.0, throw=False, name='D', warning=False)[source]

Return True if input array is a valid distance matrix.

Distance matrices must be 2-dimensional numpy arrays. They must have a zero-diagonal, and they must be symmetric.

Parameters
Dndarray

The candidate object to test for validity.

tolfloat, optional

The distance matrix should be symmetric. tol is the maximum difference between entries ij and ji for the distance metric to be considered symmetric.

throwbool, optional

An exception is thrown if the distance matrix passed is not valid.

namestr, optional

The name of the variable to checked. This is useful if throw is set to True so the offending variable can be identified in the exception message when an exception is thrown.

warningbool, optional

Instead of throwing an exception, a warning message is raised.

Returns
validbool

True if the variable D passed is a valid distance matrix.

Notes

Small numerical differences in D and D.T and non-zeroness of the diagonal are ignored if they are within the tolerance specified by tol.

Previous topic

scipy.spatial.distance.directed_hausdorff

Next topic

scipy.spatial.distance.is_valid_y