code: def sample_discrete_from_log(p_log,axis=0,dtype=np.int32):
      'samples log probability array along specified axis'
      cumvals = np.exp(p_log - np.expand_dims(p_log.max(axis),axis)).cumsum(axis) # cumlogaddexp
      thesize = np.array(p_log.shape)
      thesize[axis] = 1
      randvals = random(size=thesize) * \
              np.reshape(cumvals[[slice(None) if i is not axis else -1
                  for i in range(p_log.ndim)]],thesize)
      return np.sum(randvals > cumvals,axis=axis,dtype=dtypef sample_discrete_from_log(p_log,axis=0,dtype=np.int32):
      'samples log probability array along specified axis'
      cumvals = np.exp(p_log - np.expand_dims(p_log.max(axis),axis)).cumsum(axis) # cumlogaddexp
      thesize = np.array(p_log.shape)
      thesize[axis] = 1
      randvals = random(size=thesize) * \
              np.reshape(cumvals[[slice(None) if i is not axis else -1
                  for i in range(p_log.ndim)]],thesize)
      return np.sum(randvals > cumvals,axis=axis,dtype=dtype)
docs: samples log probability array along specified axis