code: def trace_cov(trace, vars=None, model=None):
      """
      Calculate the flattened covariance matrix using a sample trace
  
      Useful if you want to base your covariance matrix for further sampling on some initial samples.
  
      Parameters
      ----------
      trace: Trace
      vars: list
          variables for which to calculate covariance matrix
  
      Returns
      -------
      r: array (n,n)
          covariance matrix
      """
      model = modelcontext(model)
  
      if model is not None:
          vars = model.free_RVs
      elif vars is None:
          vars = trace.varnames
  
      def flat_t(var):
          x = trace[get_var_name(var)]
          return x.reshape(
              (x.shape[0], np.prod(x.shape[1:], dtype=int))
          )
  
      return np.cov(np.concatenate(list(map(flat_t, vars)), 1).T)
  
file_path: pymc/pymc/tuning/scaling.py
imports: import numpy
  from numpy import exp, log, sqrt
  from pymc.blocking import DictToArrayBijection
  from pymc.model import Point, modelcontext
  from pymc.pytensorf import hessian_diag
  from pymc.util import get_var_name
label_desc: Use image node_id 9 for calling a global function with example usage: trace_cov(trace, vars, model) and returns: np, x