biom.table.Table.iter — biom-format.org

# biom-format.org

## biom.table.Table.iter

`Table.` `iter`(dense=True, axis='sample')

  Yields `(value, id, metadata)`

  Parameters: | dense : bool, optional Defaults to `True`. If `False`, yield compressed sparse row or compressed sparse columns if axis is ‘observation’ or ‘sample’, respectively. axis : {‘sample’, ‘observation’}, optional The axis to iterate over.
  Returns: | GeneratorType A generator that yields (values, id, metadata)

  Examples

      >>> import numpy as np
      >>> from biom.table import Table

  Create a 2x3 BIOM table:

      >>> data = np.asarray([[0, 0, 1], [1, 3, 42]])
      >>> table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'Z3'])

  Iter over samples and keep those that start with an Z:

      >>> [(values, id, metadata)
      ...     for values, id, metadata in table.iter() if id[0]=='Z']
      [(array([  1.,  42.]), 'Z3', None)]

  Iter over observations and add the 2nd column of the values

      >>> col = [values[1] for values, id, metadata in table.iter()]
      >>> sum(col)
      46.0