skbio.stats.composition.closure#

skbio.stats.composition.closure(mat, axis=-1, validate=True)[source]#

Perform closure to ensure that all components of each composition sum to 1.

Changed in version 0.7.0: The function now works on any dimension in arrays of any number of dimensions.

Parameters:
matarray_like of shape (…, n_components, …)

A matrix of compositions.

axisint, optional

Axis along which closure will be performed. That is, each vector along this axis is considered as a composition. Default is the last axis (-1).

Added in version 0.7.0.

validatebool, default True

Check if the compositions are legitimate.

Added in version 0.7.0.

Returns:
ndarray of shape (…, n_components, …)

The matrix where all components of each composition sum to 1.

Examples

>>> import numpy as np
>>> from skbio.stats.composition 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]])