code: def permutation_helper(random_state, n, shape):
      """
      Helper function to generate permutations from integers.
  
      permutation_helper(random_state, n, (1,)) will generate a permutation of
      integers 0..n-1.
      In general, it will generate as many such permutation as required by shape.
      For instance, if shape=(p,q), p*q permutations will be generated, and the
      output shape will be (p,q,n), because each permutation is of size n.
  
      If you wish to perform a permutation of the elements of an existing vector,
      see shuffle_row_elements.
  
      This is a generalization of numpy.random.permutation to tensors.
      Otherwise it behaves the same.
  
      """
      # n should be a 0-dimension array
      assert n.shape == ()
      # Note that it is important to convert `n` into an integer, because if it
      # is a long, the numpy permutation function will crash on Windows.
      n = int(n.item())
  
      if shape is None:
          # Draw only one permutation, equivalent to shape = ()
          shape = ()
      out_shape = list(shape)
      out_shape.append(n)
      out = np.empty(out_shape, int)
      for i in np.ndindex(*shape):
          out[i] = random_state.permutation(n)
  
      # print 'RETURNING', out.shape
      return out
  
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 11 for calling a global function with example usage: permutation_helper(random_state, n, shape) and returns: out