code: def random_choice(p, size):
      """Return draws from categorical probability functions
  
      Parameters
      ----------
      p : array
          Probability of each class. If p.ndim > 1, the last axis is
          interpreted as the probability of each class, and numpy.random.choice
          is iterated for every other axis element.
      size : int or tuple
          Shape of the desired output array. If p is multidimensional, size
          should broadcast with p.shape[:-1].
  
      Returns
      -------
      random_sample : array
  
      """
      k = p.shape[-1]
  
      if p.ndim > 1:
          # If p is an nd-array, the last axis is interpreted as the class
          # probability. We must iterate over the elements of all the other
          # dimensions.
          # We first ensure that p is broadcasted to the output's shape
          size = to_tuple(size) + (1,)
          p = np.broadcast_arrays(p, np.empty(size))[0]
          out_shape = p.shape[:-1]
          # np.random.choice accepts 1D p arrays, so we semiflatten p to
          # iterate calls using the last axis as the category probabilities
          p = np.reshape(p, (-1, p.shape[-1]))
          samples = np.array([np.random.choice(k, p=p_) for p_ in p])
          # We reshape to the desired output shape
          samples = np.reshape(samples, out_shape)
      else:
          samples = np.random.choice(k, p=p, size=size)
      return samples
  
imports: import warnings
  from functools import partial
  from typing import Iterable
  import numpy
  import pytensor
  import pytensor.tensor
  import scipy.linalg
  import scipy.stats
  from pytensor.graph.basic import Apply, Variable
  from pytensor.graph.op import Op
  from pytensor.scalar import UnaryScalarOp, upgrade_to_float_no_complex
  from pytensor.tensor import gammaln
  from pytensor.tensor.elemwise import Elemwise
  from pymc.distributions.shape_utils import to_tuple
  from pymc.logprob.utils import CheckParameterValue
  from pymc.pytensorf import floatX
label_desc: Use image node_id 14 for calling a global function with example usage: random_choice(p, size) and returns: samples