shannon_entropy¶
- shannon_entropy(pvec, base=2)[source]¶
Compute the Shannon entropy of a probability vector.
The shannon entropy of a probability vector \(\vec{p} = [p_0, ..., p_{n-1}]\) is defined as
where \(b\) is the log base and (default 2), and \(0 \log_b(0) \equiv 0\).
- Parameters
pvec (array_like) – a probability vector.
base (int) – the base of the logarithm [Default: 2].
- Returns
The Shannon entropy H(pvec).
- Return type
float