code: def log_multivariate_gaussian(x, mu, V, Vinv=None, method=1):
      """Evaluate a multivariate gaussian N(x|mu, V)
  
      This allows for multiple evaluations at once, using array broadcasting
  
      Parameters
      ----------
      x: array_like
          points, shape[-1] = n_features
  
      mu: array_like
          centers, shape[-1] = n_features
  
      V: array_like
          covariances, shape[-2:] = (n_features, n_features)
  
      Vinv: array_like or None
          pre-computed inverses of V: should have the same shape as V
  
      method: integer, optional
          method = 0: use cholesky decompositions of V
          method = 1: use explicit inverse of V
  
      Returns
      -------
      values: ndarray
          shape = broadcast(x.shape[:-1], mu.shape[:-1], V.shape[:-2])
  
      Examples
      --------
  
      >>> x = [1, 2]
      >>> mu = [0, 0]
      >>> V = [[2, 1], [1, 2]]
      >>> log_multivariate_gaussian(x, mu, V)
      -3.3871832107434003
      """
      x = np.asarray(x, dtype=float)
      mu = np.asarray(mu, dtype=float)
      V = np.asarray(V, dtype=float)
  
      ndim = x.shape[-1]
      x_mu = x - mu
  
      if V.shape[-2:] != (ndim, ndim):
          raise ValueError("Shape of (x-mu) and V do not match")
  
      Vshape = V.shape
      V = V.reshape([-1, ndim, ndim])
  
      if Vinv is not None:
          assert Vinv.shape == Vshape
          method = 1
  
      if method == 0:
          Vchol = np.array(
              [
                  linalg.cholesky(V[i], lower=True)
                  for i in range(V.shape[0])
              ]
          )
  
          # we may be more efficient by using scipy.linalg.solve_triangular
          # with each cholesky decomposition
          VcholI = np.array(
              [linalg.inv(Vchol[i]) for i in range(V.shape[0])]
          )
          logdet = np.array(
              [
                  2 * np.sum(np.log(np.diagonal(Vchol[i])))
                  for i in range(V.shape[0])
              ]
          )
  
          VcholI = VcholI.reshape(Vshape)
          logdet = logdet.reshape(Vshape[:-2])
  
          VcIx = np.sum(
              VcholI
              * x_mu.reshape(x_mu.shape[:-1] + (1,) + x_mu.shape[-1:]),
              -1,
          )
          xVIx = np.sum(VcIx**2, -1)
  
      elif method == 1:
          if Vinv is None:
              Vinv = np.array(
                  [linalg.inv(V[i]) for i in range(V.shape[0])]
              ).reshape(Vshape)
          else:
              assert Vinv.shape == Vshape
  
          logdet = np.log(
              np.array([linalg.det(V[i]) for i in range(V.shape[0])])
          )
          logdet = logdet.reshape(Vshape[:-2])
  
          xVI = np.sum(x_mu.reshape(x_mu.shape + (1,)) * Vinv, -2)
          xVIx = np.sum(xVI * x_mu, -1)
  
      else:
          raise ValueError("unrecognized method %s" % method)
  
      return -0.5 * ndim * np.log(2 * np.pi) - 0.5 * (logdet + xVIx)
  
file_path: astroML/astroML/utils/utils.py
imports: import numpy
  from scipy import linalg
  from sklearn.utils import check_random_state
  from astroML.utils.decorators import deprecated
  from astroML.utils.exceptions import AstroMLDeprecationWarning
label_desc: Use image node_id 2 for calling a global function with example usage: log_multivariate_gaussian(x, mu, V, Vinv, method) and returns: unknown