skbio.stats.distance.SymmetricMatrix.from_iterable#
- classmethod SymmetricMatrix.from_iterable(iterable, metric, key=None, keys=None, validate=True, condensed=False, diagonal=0.0)[source]#
Create a symmetric matrix from an iterable given a metric.
- Parameters:
- iterableiterable
Objects to compute pairwise relationships on.
- metriccallable
A function that takes two arguments and returns a float representing the relationship between the two objects.
- keycallable or str, optional
A function that takes one argument and returns a string representing the ID of the object. Alternatively, a key to the
metadataproperty if exists for each object in theiterable. If None, the default IDs will be used.- keysiterable of str, optional
IDs of the objects. Must be the same length as
iterable.- validateboolean, optional
If True, all pairwise relationships are computed, including upper and lower triangles and the diagonal. If False,
metricis assumed to be symmetric and only the lower triangle (excluding the diagonal) is computed, thereby saving compute.- condensedbool, optional
Store the data in a 2-D redundant form (False, default) or a 1-D condensed form (True).
- diagonalfloat or array_like, optional
Value(s) with which to fill the diagonal of the matrix. Relevant only when
validateis False.
- Returns:
- PairwiseMatrix
The
metricapplied to all pairwise elements in theiterable.
- Raises:
- ValueError
If
keyandkeysare both provided.