skbio.stats.distance.SymmetricMatrix.from_iterable#

classmethod SymmetricMatrix.from_iterable(iterable, metric, key=None, keys=None, validate=True, diagonal=0.0, condensed=False)[source]#

Create PairwiseMatrix from an iterable given a metric.

Parameters:
iterableiterable

Iterable containing objects to compute pairwise dissimilarities on.

metriccallable

A function that takes two arguments and returns a float representing the dissimilarity 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 dissimilarity 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 relationships are computed, including upper and lower triangles and the diagonal. If False, metric is assumed to be hollow and symmetric and only the lower triangle (excluding the diagonal) is computed. Pass validate=False if you are sure metric is hollow and symmetric for improved performance.

diagonalfloat or np.ndarray, optional

If float, this value will be used to fill the diagonal of the matrix. If array, this array will be used to fill the diagonal of the matrix. Defaults to 0.0.

condensedbool, optional

If False (default), the underlying data structure will be the redundant form (2D) of the matrix. If True, the underlying data structure will be the condensed form (1D) of the matrix.

Returns:
PairwiseMatrix

The metric applied to all pairwise elements in the iterable.

Raises:
ValueError

If key and keys are both provided.