Skip to main content
`Ctrl`+`K`

# skbio.stats.composition.closure

skbio.stats.composition.closure(mat)

  Perform closure to ensure that all elements add up to 1.

  Parameters:
    mat array_like of shape (n_compositions, n_components)

      A matrix of proportions.

  Returns:
    ndarray of shape (n_compositions, n_components)

      The matrix where all of the values are non-zero and each composition (row) adds up to 1.

  Raises:
    ValueError

      If any values are negative.

    ValueError

      If the matrix has more than two dimensions.

    ValueError

      If there is a row that has all zeros.

  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]])