code: def sample_bernoulli(p, temperature=1):
      """Sample an array of Bernoullis.
  
      Args:
        p: an array of Bernoulli probabilities.
        temperature: if not 1, transform the distribution by dividing the log
            probabilities and renormalizing. Values greater than 1 increase entropy,
            values less than 1 decrease entropy. A value of 0 yields a deterministic
            distribution that chooses the mode.
  
      Returns:
        A binary array of sampled values, the same shape as `p`.
      """
      if temperature == 0.0:
          sampled = p > 0.5
      else:
          pp = np.stack([p, 1 - p])
          logpp = np.log(pp)
          logpp /= temperature
          logpp -= logpp.max(axis=0, keepdims=True)
          p = np.exp(logpp)
          p /= p.sum(axis=0)
          print(
              "%.5f < %.5f < %.5f < %.5f < %.5g"
              % (
                  np.min(p),
                  np.percentile(p, 25),
                  np.percentile(p, 50),
                  np.percentile(p, 75),
                  np.max(p),
              )
          )
  
          sampled = np.random.random(p.shape) < p
      return sampled
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import contextlib
  import datetime
  import numbers
  import pdb
  import tempfile
  import time
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling a global function with example usage: sample_bernoulli(p, temperature) and returns: sampled