polars.Series.entropy#
- Series.entropy( ) float | None[source]#
Computes the entropy.
Uses the formula
-sum(pk * log(pk))wherepkare discrete probabilities.0 * log(0)is taken as 0 and null values are ignored. Negative values give NaN. Withnormalize=True, input that sums to zero (including empty, all-null and all-zero input) gives NaN; withnormalize=Falseit gives 0.- Parameters:
- base
Given base, defaults to
e- normalize
Normalize pk if it doesn’t sum to 1.
Examples
>>> a = pl.Series([0.99, 0.005, 0.005]) >>> a.entropy(normalize=True) 0.06293300616044681 >>> b = pl.Series([0.65, 0.10, 0.25]) >>> b.entropy(normalize=True) 0.8568409950394724