The Shannon entropy of a discrete XX with p(x)=P(X=x)p(x)=\mathbb{P}(X=x) is

H(X)  =  −∑xp(x) log⁡p(x),H(X) \;=\; -\sum_x p(x)\,\log p(x),

with the convention 0log⁡0=00\log 0=0. The value may be +∞+\infty. Unless stated otherwise, log⁡\log denotes the natural logarithm; changing its base rescales HH by a constant factor.

Equivalent characterizations

Equivalently, H(X)H(X) is the of −log⁡p(X)-\log p(X) under the distribution of XX.

Remarks

Shannon entropy is closely related to and is a central quantity in information theory.

Examples
  • If X∼Bernoulli(p)X\sim\mathrm{Bernoulli}(p), then H(X)=−plog⁡p−(1−p)log⁡(1−p)H(X)=-p\log p-(1-p)\log(1-p).
  • If XX is uniform on {1,2,3,4,5,6}\{1,2,3,4,5,6\}, then H(X)=log⁡6H(X)=\log 6.