DistanceMatrix.
__getitem__
(index)[source]¶Slice into dissimilarity data by object ID or numpy indexing.
State: Experimental as of 0.4.0.
Extracts data from the dissimilarity matrix by object ID, a pair of IDs, or numpy indexing/slicing.
index (str, two-tuple of str, or numpy index) –
index can be one of the following forms: an ID, a pair of IDs, or a numpy index.
If index is a string, it is assumed to be an ID and a
numpy.ndarray
row vector is returned for the corresponding ID.
Note that the ID’s row of dissimilarities is returned, not its
column. If the matrix is symmetric, the two will be identical, but
this makes a difference if the matrix is asymmetric.
If index is a two-tuple of strings, each string is assumed to be
an ID and the corresponding matrix element is returned that
represents the dissimilarity between the two IDs. Note that the
order of lookup by ID pair matters if the matrix is asymmetric: the
first ID will be used to look up the row, and the second ID will be
used to look up the column. Thus, dm['a', 'b']
may not be the
same as dm['b', 'a']
if the matrix is asymmetric.
Otherwise, index will be passed through to
DissimilarityMatrix.data.__getitem__
, allowing for standard
indexing of a numpy.ndarray
(e.g., slicing).
Indexed data, where return type depends on the form of index (see description of index for more details).
ndarray or scalar
MissingIDError – If the ID(s) specified in index are not in the dissimilarity matrix.
Notes
The lookup based on ID(s) is quick.