code: def reduce_dimensions(
      tensor, average_axes=None, sum_axes=None, keepdims=None
  ):
      """Average or sum over dimensions of :attr:`tensor`.
  
      :attr:`average_axes` and :attr:`sum_axes` must be mutually exclusive. That
      is, elements in `average_axes` must not be contained in
      `sum_axes`, and vice versa.
  
      Args:
          tensor: A tensor to reduce.
          average_axes (optional): A (list of) `int` that indicates the
              dimensions to reduce by taking average.
          sum_axes (optional): A (list of) `int` that indicates the
              dimensions to reduce by taking sum.
          keepdims (optional): If `True`, retains reduced dimensions with
              length 1.
      """
      reduced_axes = set()
      if average_axes is not None:
          if not isinstance(average_axes, (list, tuple)):
              average_axes = [average_axes]
          if len(average_axes) > 0:
              tensor = tf.reduce_mean(
                  tensor, axis=average_axes, keepdims=True
              )
              reduced_axes.update(average_axes)
  
      if sum_axes is not None:
          if not isinstance(sum_axes, (list, tuple)):
              sum_axes = [sum_axes]
          if len(sum_axes) > 0:
              tensor = tf.reduce_sum(
                  tensor, axis=sum_axes, keepdims=True
              )
              reduced_axes.update(sum_axes)
  
              if average_axes is not None:
                  if len(reduced_axes) != len(average_axes) + len(
                      sum_axes
                  ):
                      raise ValueError(
                          "`average_axes` and `sum_axes` must not "
                          "have overlapped elements."
                      )
      if not keepdims:
          tensor = tf.squeeze(tensor, axis=list(reduced_axes))
  
      return tensor
  
imports: import numpy
  import tensorflow
  from tensorflow.python.ops import rnn
  from texar.tf.utils.shapes import mask_sequences
label_desc: Use image node_id 3 for calling a global function with example usage: reduce_dimensions(tensor, average_axes, sum_axes, keepdims) and returns: tensor