code: def kl_divergence(p, q):
      
      # make sure numpy arrays are floats
      p = p.astype(float)
      q = q.astype(float)
  
      # compute kl divergence
      kl = np.sum(np.where(p!=0, p*np.log2(p/q), 0))
      return kl
docs: Compute the Kullback-Leibler (KL) divergence for discrete distributions.
  
      Parameters
      ----------
      p : np.array
          "Ideal"/"true" Probability distribution
      q : np.array
          Approximation of probability distribution p
  
      Returns
      -------
      kl : float
          KL divergence of approximating p with the distribution q