def kldivergence(p, q):
    'Kullback-Leibler divergence D(P || Q) for discrete distributions\n    Parameters\n    ----------\n    p, q : array-like, dtype=float, shape=n\n    Discrete probability distributions.\n    '
    p = np.asarray(p, dtype=np.float)
    q = np.asarray(q, dtype=np.float)
    return np.sum(np.where((p != 0), (p * np.log((p / q))), 0))
Kullback-Leibler divergence D(P || Q) for discrete distributions
Parameters
----------
p, q : array-like, dtype=float, shape=n
Discrete probability distributions.
def kldivergence(p, q):
    'Kullback-Leibler divergence D(P || Q) for discrete distributions\n    Parameters\n    ----------\n    p, q : array-like, dtype=float, shape=n\n    Discrete probability distributions.\n    '
    p = np.asarray(p, dtype=np.float)
    q = np.asarray(q, dtype=np.float)
    return np.sum(np.where((p != 0), (p * np.log((p / q))), 0))