How KL and Jensen-Shannon divergence are computed
KL divergence. For discrete distributions P and Q over the same outcomes, KL(P||Q) = sum of p(i) times log(p(i) / q(i)). It measures the extra information, in bits for log base 2 or nats for the natural log, you pay when you encode data drawn from P with a code built for Q. It is always at least 0 and equals 0 only when P and Q are identical.
Worked example. Wikipedia's example uses P = (0.36, 0.48, 0.16), a binomial with N = 2 and p = 0.4, and Q uniform at 1/3 each. The terms are 0.36 ln(1.08) = 0.02771, 0.48 ln(1.44) = 0.17503 and 0.16 ln(0.48) = -0.11744, so KL(P||Q) = 0.0852996 nats. Reversed, KL(Q||P) = 0.097455 nats. The same inputs give 0.123061 bits, and scipy.stats.entropy returns identical values in our unit tests.
Jensen-Shannon. Build the mixture M = (P + Q) / 2, then JSD = 0.5 KL(P||M) + 0.5 KL(Q||M). With log base 2 it always falls between 0 and 1, and its square root, the JS distance, is a true metric. For the example above the JS distance is 0.180008 in base 2, which matches scipy.spatial.distance.jensenshannon.