Skip to main content
`Ctrl`+`K`

# skbio.stats.composition.closure

skbio.stats.composition.closure(mat, axis=-1, validate=True)

  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:
    mat array_like of shape (…, n_components, …)

      A matrix of compositions.

    axis int, 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.

    validate bool, 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.

  Notes

  Note

  This function supports the Python array API standard. Compatible array backends:

  Backend | CPU | GPU
  --- | --- | ---
  NumPy | ✓ | n/a
  CuPy | n/a | ✓
  PyTorch | ✓ | ✓
  JAX | ✓ | ✓
  Dask | ✓ | n/a

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