skbio.table.Table.iter_pairwise#
- Table.iter_pairwise(dense=True, axis='sample', tri=True, diag=False)[source]#
Pairwise iteration over self
- Parameters:
- densebool, optional
Defaults to
True
. IfFalse
, yield compressed sparse row or compressed sparse columns if axis is ‘observation’ or ‘sample’, respectively.- axis{‘sample’, ‘observation’}, optional
The axis to iterate over.
- tribool, optional
If
True
, just yield [i, j] and not [j, i]- diagbool, optional
If
True
, yield [i, i]
- Returns:
- GeneratorType
Yields [(val_i, id_i, metadata_i), (val_j, id_j, metadata_j)]
- Raises:
- UnknownAxisError
Examples
>>> from biom import example_table
By default, only the upper triangle without the diagonal of the resulting pairwise combinations is yielded.
>>> iter_ = example_table.iter_pairwise() >>> for (val_i, id_i, md_i), (val_j, id_j, md_j) in iter_: ... print(id_i, id_j) S1 S2 S1 S3 S2 S3
The full pairwise combinations can also be yielded though.
>>> iter_ = example_table.iter_pairwise(tri=False, diag=True) >>> for (val_i, id_i, md_i), (val_j, id_j, md_j) in iter_: ... print(id_i, id_j) S1 S1 S1 S2 S1 S3 S2 S1 S2 S2 S2 S3 S3 S1 S3 S2 S3 S3