code: def seq_to_batch(tensor_sequence, flat=False):
      """
      Transform a sequence of Tensors, into a batch of Tensors for recurrent policies
  
      :param tensor_sequence: (TensorFlow Tensor) The input tensor to batch
      :param flat: (bool) If the input Tensor is flat
      :return: (TensorFlow Tensor) batch of Tensors for recurrent policies
      """
      shape = tensor_sequence[0].get_shape().as_list()
      if not flat:
          assert len(shape) > 1
          n_hidden = tensor_sequence[0].get_shape()[-1].value
          return tf.reshape(
              tf.concat(axis=1, values=tensor_sequence), [-1, n_hidden]
          )
      else:
          return tf.reshape(
              tf.stack(values=tensor_sequence, axis=1), [-1]
          )
  
imports: import os
  import collections
  import functools
  import multiprocessing
  from typing import Set
  import numpy
  import tensorflow
label_desc: Use image node_id 3 for calling a global function with example usage: seq_to_batch(tensor_sequence, flat) and returns: tf, tf