Fork me on GitHub

biom-format.org

biom.table.Table.reduce

«  biom.table.Table.partition   ::   Contents   ::   biom.table.Table.sort  »

biom.table.Table.reduce

Table.reduce(f, axis)

Reduce over axis using function f

Parameters:

f : function

The function to use for the reduce operation

axis : {‘sample’, ‘observation’}

The axis on which to operate

Returns:

numpy.array

A one-dimensional array representing the reduced rows (observations) or columns (samples) of the data matrix

Raises:

UnknownAxisError

If axis is neither “sample” nor “observation”

TableException

If the table’s data matrix is empty

Examples

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

Create a 2x3 table

>>> data = np.asarray([[0, 0, 1], [1, 3, 42]])
>>> table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3'],
...               [{'foo': 'bar'}, {'x': 'y'}], None)

Create a reduce function

>>> func = lambda x, y: x + y

Reduce table on samples

>>> table.reduce(func, 'sample') 
array([  1.,   3.,  43.])

Reduce table on observations

>>> table.reduce(func, 'observation') 
array([  1.,  46.])

«  biom.table.Table.partition   ::   Contents   ::   biom.table.Table.sort  »