code: def sample(self, rstate=None, return_q=False):
          
  
          if rstate is None:
              rstate = np.random
  
          # If there is only one ellipsoid, sample from it.
          if self.nells == 1:
              x = self.ells[0].sample(rstate=rstate)
              idx = 0
              q = 1
              if return_q:
                  return x, idx, q
              else:
                  return x, idx
  
          # Select an ellipsoid at random proportional to its volume.
          idx = rstate.choice(self.nells, p=self.vols/self.vol_tot)
  
          # Select a point from the chosen ellipsoid.
          x = self.ells[idx].sample(rstate=rstate)
  
          # Check how many ellipsoids the point lies within, passing over
          # the `idx`-th ellipsoid `x` was sampled from.
          q = self.overlap(x, j=idx) + 1
  
          if return_q:
              # If `q` is being returned, assume the user wants to
              # explicitly apply the `1. / q` acceptance criterion to
              # properly sample from the union of ellipsoids.
              return x, idx, q
          else:
              # If `q` is not being returned, assume the user wants this
              # done internally.
              while rstate.rand() > (1. / q):
                  idx = rstate.choice(self.nells, p=self.vols/self.vol_tot)
                  x = self.ells[idx].sample(rstate=rstate)
                  q = self.overlap(x, j=idx) + 1
  
              return x, idx
docs: Sample a point uniformly distributed within the *union* of ellipsoids.
  
          Returns
          -------
          x : `~numpy.ndarray` with shape (ndim,)
              A coordinate within the set of ellipsoids.
  
          idx : int
              The index of the ellipsoid `x` was sampled from.
  
          q : int, optional
              The number of ellipsoids `x` falls within.