code: def multinomial(
      random_state,
      size=None,
      n=1,
      pvals=[0.5, 0.5],
      ndim=None,
      dtype="int64",
  ):
      """
      Sample from one or more multinomial distributions defined by
      one-dimensional slices in pvals.
  
      Parameters
      ----------
      pvals
          A tensor of shape "nmulti+(L,)" describing each multinomial
          distribution.  This tensor must have the property that
          numpy.allclose(pvals.sum(axis=-1), 1) is true.
      size
          A vector of shape information for the output; this can also
          specify the "nmulti" part of pvals' shape.  A -1 in the k'th position
          from the right means to borrow the k'th position from the
          right in nmulti. (See examples below.)
          Default ``None`` means size=nmulti.
      n
          The number of experiments to simulate for each
          multinomial. This can be a scalar, or tensor, it will be
          broadcasted to have shape "nmulti".
      dtype
          The dtype of the return value (which will represent counts)
  
      Returns
      -------
      tensor
          Tensor of len(size)+1 dimensions, and shape[-1]==L, with
          the specified ``dtype``, with the experiment counts. See
          examples to understand the shape of the return value, which is
          derived from both size and pvals.shape. In return value rval,
          "numpy.allclose(rval.sum(axis=-1), n)" will be true.
  
      Extended Summary
      ----------------
      For example, to simulate n experiments from each multinomial in a batch of
      size B:
  
          size=None, pvals.shape=(B,L) --> rval.shape=[B,L]
  
          rval[i,j] is the count of possibility j in the i'th distribution (row)
          in pvals.
  
      Using size:
  
          size=(1,-1), pvals.shape=(A,B,L)
          --> rval.shape=[1,B,L], and requires that A==1.
  
          rval[k,i,j] is the count of possibility j in the distribution specified
          by pvals[k,i].
  
      Using size for broadcasting of pvals:
  
          size=(10, 1, -1), pvals.shape=(A, B, L)
          --> rval.shape=[10,1,B,L], and requires that A==1.
  
          rval[l,k,i,j] is the count of possibility j in the
          distribution specified by pvals[k,i], in the l'th of 10
          draws.
  
      """
      n = tensor.as_tensor_variable(n)
      pvals = tensor.as_tensor_variable(pvals)
      # until ellipsis is implemented (argh)
      tmp = pvals.T[0].T
      ndim, size, bcast = _infer_ndim_bcast(ndim, size, n, tmp)
      bcast = bcast + (pvals.type.broadcastable[-1],)
      op = RandomFunction(
          multinomial_helper,
          tensor.TensorType(dtype=dtype, broadcastable=bcast),
          ndim_added=1,
      )
      return op(random_state, size, n, pvals)
  
imports: from __future__ import absolute_import, print_function, division
  import sys
  from copy import copy
  import numpy
  from six import string_types
  from six.moves import reduce, xrange
  import theano
  from theano import tensor
  from theano.tensor import opt
  from theano import gof
  from theano.compile import optdb
label_desc: Use image node_id 14 for calling a global function with example usage: multinomial(random_state, size, n, pvals, ndim, dtype) and returns: op