skbio.stats.distance.DistanceMatrix.from_iterable

classmethod DistanceMatrix.from_iterable(iterable, metric, key=None, keys=None)[source]

Create DistanceMatrix from all pairs in an iterable given a metric.

State: Experimental as of 0.4.1.

Parameters:

iterable : iterable

Iterable containing objects to compute pairwise distances on.

metric : callable

A function that takes two arguments and returns a float representing the distance between the two arguments.

key : callable 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.

keys : iterable, optional

An iterable of the same length as iterable. Each element will be used as the respective key.

Returns:

DistanceMatrix

The metric applied to all pairwise elements in the iterable.

Raises:

ValueError

If key and keys are both provided.

Notes

Symmetry and hollowness are assumed when calculating the distances via metric. Therefore, distances are only computed for the strictly upper/lower triangle.