code: def sample_discrete(values, weights, size=1, seed=None):
      """
      Generate a sample of given size, given a probability mass function.
  
      Parameters
      ----------
      values: numpy.array
          Array of all possible values that the random variable can take.
  
      weights: numpy.array or list of numpy.array
          Array(s) representing the PMF of the random variable.
  
      size: int
          Size of the sample to be generated.
  
      seed: int (default: None)
          If a value is provided, sets the seed for numpy.random.
  
      Returns
      -------
      samples: numpy.array
          Array of values of the random variable sampled from the given PMF.
  
      Example
      -------
      >>> import numpy as np
      >>> from pgmpy.utils.mathext import sample_discrete
      >>> values = np.array(['v_0', 'v_1', 'v_2'])
      >>> probabilities = np.array([0.2, 0.5, 0.3])
      >>> sample_discrete(values, probabilities, 10, seed=0).tolist()
      ['v_1', 'v_2', 'v_1', 'v_1', 'v_1', 'v_1', 'v_1', 'v_2', 'v_2', 'v_1']
      """
      if seed is not None:
          np.random.seed(seed)
      weights = compat_fns.to_numpy(weights)
      if weights.ndim == 1:
          return np.random.choice(
              compat_fns.to_numpy(values),
              size=size,
              p=_adjusted_weights(weights),
          )
      else:
          samples = np.zeros(size, dtype=int)
          unique_weights, counts = np.unique(
              weights, axis=0, return_counts=True
          )
          for index, size in enumerate(counts):
              samples[
                  (weights == unique_weights[index]).all(axis=1)
              ] = np.random.choice(
                  compat_fns.to_numpy(values),
                  size=size,
                  p=_adjusted_weights(unique_weights[index]),
              )
          return samples
  
file_path: pgmpy/pgmpy/utils/mathext.py
imports: from collections import namedtuple
  from itertools import chain, combinations
  import numpy
  from pgmpy import config
  from pgmpy.global_vars import logger
  from pgmpy.utils import compat_fns
label_desc: Use image node_id 3 for calling a global function with example usage: sample_discrete(values, weights, size, seed) and returns: np, samples