Skip to main content
`Ctrl`+`K`

# scipy.special.entr

scipy.special.entr(x, out=None) = <ufunc 'entr'>

  Elementwise function for computing entropy.

  \[\begin{split}\text{entr}(x) = \begin{cases} - x \log(x) & x > 0 \\ 0 & x = 0 \\ -\infty & \text{otherwise} \end{cases}\end{split}\]
  Parameters:
    x ndarray

      Input array.

    out ndarray, optional

      Optional output array for the function values

  Returns:
    res scalar or ndarray

      The value of the elementwise entropy function at the given points x.

  See also

  `kl_div`, `rel_entr`, `scipy.stats.entropy`

  Notes

  Added in version 0.15.0.

  This function is concave.

  The origin of this function is in convex programming; see [1]. Given a probability distribution \(p_1, \ldots, p_n\), the definition of entropy in the context of information theory is

  \[\sum_{i = 1}^n \mathrm{entr}(p_i).\]

  To compute the latter quantity, use `scipy.stats.entropy`.

  `entr` has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable `SCIPY_ARRAY_API=1` and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

  Library | CPU | GPU
  --- | --- | ---
  NumPy | ✅ | n/a
  CuPy | n/a | ✅
  PyTorch | ✅ | ✅
  JAX | ✅ | ✅
  Dask | ✅ | n/a

  See Support for the array API standard for more information.

  References

  [1]

  Boyd, Stephen and Lieven Vandenberghe. Convex optimization. Cambridge University Press, 2004. DOI:https://doi.org/10.1017/CBO9780511804441