class_docstr: Layer uses applies weighted elementwise addition to multiple outputs.
  Weight can be control using separate input known as **gate**. Number
  of outputs from the gate has to be equal to the number of networks,
  since each value from the weight will be a weight per each network.
  
  Layer expects gate as a first input, but it can be controlled with
  the ``gate_index`` parameter.
  
  Parameters
  ----------
  gate_index : int
      Input layers passed as a list and current variable specifies
      index in which it can find gating network. Defaults to ``0``,
      which means that it expects to see gating layer in first position.
  
  {BaseLayer.Parameters}
  
  Methods
  -------
  {BaseLayer.Methods}
  
  Attributes
  ----------
  {BaseLayer.Attributes}
  
  Examples
  --------
  >>> from neupy.layers import *
  >>>
  >>> gate = Input(10) >> Softmax(2)
  >>> net1 = Input(20) >> Relu(10)
  >>> net2 = Input(20) >> Relu(20) >> Relu(10)
  >>>
  >>> network = (gate | net1 | net2) >> GatedAverage()
  >>> network
  [(10,), (20,), (20,)] -> [... 8 layers ...] -> 10
code: def fail_if_shape_invalid(self, input_shapes):
      n_input_layers = len(input_shapes)
  
      try:
          gate_shape = input_shapes[self.gate_index]
      except IndexError:
          raise LayerConnectionError(
              "Invalid index for gating layer. Number of input "
              "layers: {}. Gating layer index: {}"
              "".format(n_input_layers, self.gate_index)
          )
  
      other_shapes = exclude_index(input_shapes, self.gate_index)
      if gate_shape and len(gate_shape) != 2:
          raise LayerConnectionError(
              "Output from the gating network should be 2-dimensional. "
              "Output shape from gating layer: {!r}"
              "".format(gate_shape)
          )
  
      n_expected_networks = gate_shape[-1]
      # Note: -1 from all layers in order to exclude gating layer
      if n_expected_networks != (n_input_layers - 1):
          raise LayerConnectionError(
              "Gating layer can work only for combining only {} networks, "
              "got {} networks instead."
              "".format(n_expected_networks, (n_input_layers - 1))
          )
  
      for shape in other_shapes:
          if not shape.is_compatible_with(other_shapes[0]):
              raise LayerConnectionError(
                  "Output layer that has to be merged expect to "
                  "have the same shapes. Shapes: {!r}"
                  "".format(tf_utils.shape_to_tuple(other_shapes))
              )
  
imports: import copy
  from functools import reduce
  import tensorflow
  from neupy.core.properties import FunctionWithOptionsProperty, IntProperty
  from neupy.exceptions import LayerConnectionError
  from neupy.utils import tf_utils
  from .base import BaseLayer
label_desc: Use image node_id 2 for calling the GatedAverage obj's underlying member method code with example usage: obj.fail_if_shape_invalid(input_shapes) without return types