SciPy

scipy.special.kl_div

scipy.special.kl_div(x, y) = <ufunc 'kl_div'>

Elementwise function for computing Kullback-Leibler divergence.

\[\begin{split}\mathrm{kl\_div}(x, y) = \begin{cases} x \log(x / y) - x + y & x > 0, y > 0 \\ y & x = 0, y \ge 0 \\ \infty & \text{otherwise} \end{cases}\end{split}\]
Parameters:

x : ndarray

First input array.

y : ndarray

Second input array.

Returns:

res : ndarray

Output array.

See also

entr, rel_entr

Notes

This function is non-negative and is jointly convex in x and y.

New in version 0.15.0.

Previous topic

scipy.special.rel_entr

Next topic

scipy.special.huber