composition_stats.closure¶
- composition_stats.closure(mat, *, out=None)¶
Performs closure to ensure that all elements add up to 1.
- Parameters
- matarray_like
a matrix of proportions where rows = compositions columns = components
- outarray_like or None, optional
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.
- Returns
- array_like, np.float64
A matrix of proportions where all of the values are nonzero and each composition (row) adds up to 1
- Raises
- ValueError
Raises an error if any values are negative.
- ValueError
Raises an error if the matrix has more than 2 dimension.
- ValueError
Raises an error if there is a row that has all zeros.
Examples
>>> import numpy as np >>> from composition_stats import closure >>> X = np.array([[2, 2, 6], [4, 4, 2]]) >>> closure(X) array([[ 0.2, 0.2, 0.6], [ 0.4, 0.4, 0.2]])