code: def multinomial(probabilities):
      """
      Generate samples form a miltivariate distribution
  
      Parameters
      ----------
      probabilities: array of shape (nelements, nclasses):
                  likelihood of each element belongin to each class
                  each row is assumedt to sum to 1
                  One sample is draw from each row, resulting in
  
      Returns
      -------
      z array of shape (nelements): the draws,
        that take values in [0..nclasses-1]
      """
      nvox = probabilities.shape[0]
      nclasses = probabilities.shape[1]
      cuml = np.zeros((nvox, nclasses + 1))
      cuml[:, 1:] = np.cumsum(probabilities, 1)
      aux = np.random.rand(nvox, 1)
      z = np.argmax(aux < cuml, 1) - 1
      return z
  
imports: import math
  import numpy
  import numpy.random
  from scipy.linalg import cholesky, eigvalsh, inv
  from scipy.special import gammaln
  from .gmm import GMM
  from .utils import kmeans
label_desc: Use image node_id 8 for calling a global function with example usage: multinomial(probabilities) and returns: z