dynsight.analysis.compute_shannon

dynsight.analysis.compute_shannon(data, data_range, n_bins, units='frac')[source]

Compute the Shannon entropy of a univariate data distribution.

It is normalized so that a uniform distribution has unitary entropy.

Deprecated since version v2025.08.27: This function is deprecated and will be removed after June 2026. Use analysis.shannon() instead.

Parameters:
  • data (NDArray[np.float64]) – The dataset for which the entropy is to be computed.

  • data_range (tuple[float, float]) – A tuple (min, max) specifying the range over which the data histogram must be computed.

  • n_bins (int) – The number of bins with which the data histogram must be computed.

  • units (Literal['bit', 'nat', 'frac']) – The units of measure of the output entropy. If “frac”, entropy is normalized between 0 and 1 by dividing by log(n_bins). If “bit”, it is computed with log base 2, if “nat” with natural log.

Returns:

The value of the normalized Shannon entropy of the dataset.

Return type:

float

Example

import numpy as np
from dynsight.analysis import compute_shannon

np.random.seed(1234)
data = np.random.rand(100, 100)
data_range = (float(np.min(data)), float(np.max(data)))

data_entropy = compute_shannon(
    data,
    data_range,
    n_bins=40,
)