skbio.stats.distance.DistanceMatrix.from_iterable#
- classmethod DistanceMatrix.from_iterable(iterable, metric, key=None, keys=None, validate=True)[source]#
Create DistanceMatrix from all pairs in an iterable given a metric.
- Parameters:
- iterableiterable
Iterable containing objects to compute pairwise distances on.
- metriccallable
A function that takes two arguments and returns a float representing the distance between the two arguments.
- keycallable or metadata key, optional
A function that takes one argument and returns a string representing the id of the element in the distance matrix. Alternatively, a key to a metadata property if it exists for each element in the iterable. If None, then default ids will be used.
- keysiterable, optional
An iterable of the same length as iterable. Each element will be used as the respective key.
- validateboolean, optional
If
True
, all pairwise distances are computed, including upper and lower triangles and the diagonal, and the resulting matrix is validated for symmetry and hollowness. IfFalse
, metric is assumed to be hollow and symmetric and only the lower triangle (excluding the diagonal) is computed. Passvalidate=False
if you are sure metric is hollow and symmetric for improved performance.
- Returns:
- DistanceMatrix
The metric applied to pairwise elements in the iterable.
- Raises:
- ValueError
If key and keys are both provided.