def kld(p1, p2):
    """Compute Kullback-Leibler divergence between p1 and p2.
    It assumes that p1 and p2 are already normalized that each of them sums to 1.
    """
    return np.sum(np.where(p1 != 0, p1 * np.log(p1 / p2), 0))