code: def empirical_cdf(
      samples: np.ndarray, num_bins: int = 100
  ) -> Tuple[np.ndarray, np.ndarray]:
      """
      Calculate the empricial cdf from the given samples.
  
      Parameters
      ----------
      samples
          Tensor of samples of shape (num_samples, batch_shape)
  
      Returns
      -------
      Tensor
          Emprically calculated cdf values. shape (num_bins, batch_shape)
  
      Tensor
          Bin edges corresponding to the cdf values. shape (num_bins + 1,
          batch_shape)
      """
  
      # calculate histogram separately for each dimension in the batch size
      cdfs = []
      edges = []
  
      batch_shape = samples.shape[1:]
      agg_batch_dim = np.prod(batch_shape)
  
      samples = samples.reshape((samples.shape[0], -1))
  
      for i in range(agg_batch_dim):
          s = samples[:, i]
          bins = np.linspace(s.min(), s.max(), num_bins + 1)
          hist, edge = np.histogram(s, bins=bins)
          cdfs.append(np.cumsum(hist / len(s)))
          edges.append(edge)
  
      empirical_cdf = np.stack(cdfs, axis=-1).reshape(
          num_bins, *batch_shape
      )
      edges = np.stack(edges, axis=-1).reshape(
          num_bins + 1, *batch_shape
      )
      return empirical_cdf, edges
  
imports: import shutil
  import tempfile
  from contextlib import contextmanager
  from typing import Tuple
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: empirical_cdf(samples, num_bins) and returns: empirical_cdf,  edges