code: def neibs2images(neibs, neib_shape, original_shape, mode="valid"):
      """
      Function :func:`neibs2images <theano.sandbox.neighbours.neibs2images>`
      performs the inverse operation of
      :func:`images2neibs <theano.sandbox.neigbours.neibs2images>`. It inputs
      the output of :func:`images2neibs <theano.sandbox.neigbours.neibs2images>`
      and reconstructs its input.
  
      Parameters
      ----------
      neibs : 2d tensor
          Like the one obtained by
          :func:`images2neibs <theano.sandbox.neigbours.neibs2images>`.
      neib_shape
          `neib_shape` that was used in
          :func:`images2neibs <theano.sandbox.neigbours.neibs2images>`.
      original_shape
          Original shape of the 4d tensor given to
          :func:`images2neibs <theano.sandbox.neigbours.neibs2images>`
  
      Returns
      -------
      object
          Reconstructs the input of
          :func:`images2neibs <theano.sandbox.neigbours.neibs2images>`,
          a 4d tensor of shape `original_shape`.
  
      Notes
      -----
      Currently, the function doesn't support tensors created with
      `neib_step` different from default value. This means that it may be
      impossible to compute the gradient of a variable gained by
      :func:`images2neibs <theano.sandbox.neigbours.neibs2images>` w.r.t.
      its inputs in this case, because it uses
      :func:`images2neibs <theano.sandbox.neigbours.neibs2images>` for
      gradient computation.
  
      Examples
      --------
      Example, which uses a tensor gained in example for
      :func:`images2neibs <theano.sandbox.neigbours.neibs2images>`:
  
      .. code-block:: python
  
          im_new = neibs2images(neibs, (5, 5), im_val.shape)
          # Theano function definition
          inv_window = theano.function([neibs], im_new)
          # Function application
          im_new_val = inv_window(neibs_val)
  
      .. note:: The code will output the initial image array.
  
      """
      neibs = T.as_tensor_variable(neibs)
      neib_shape = T.as_tensor_variable(neib_shape)
      original_shape = T.as_tensor_variable(original_shape)
  
      new_neib_shape = T.stack(
          [original_shape[-1] // neib_shape[1], neib_shape[1]]
      )
      output_2d = images2neibs(
          neibs.dimshuffle("x", "x", 0, 1), new_neib_shape, mode=mode
      )
  
      if mode == "ignore_borders":
          # We use set_subtensor to accept original_shape we can't infer
          # the shape and still raise error when it don't have the right
          # shape.
          valid_shape = original_shape
          valid_shape = T.set_subtensor(
              valid_shape[2],
              (valid_shape[2] // neib_shape[0]) * neib_shape[0],
          )
          valid_shape = T.set_subtensor(
              valid_shape[3],
              (valid_shape[3] // neib_shape[1]) * neib_shape[1],
          )
          output_4d = output_2d.reshape(valid_shape, ndim=4)
          # padding the borders with zeros
          for d in [2, 3]:
              pad_shape = list(output_4d.shape)
              pad_shape[d] = original_shape[d] - valid_shape[d]
              output_4d = T.concatenate(
                  [output_4d, T.zeros(pad_shape)], axis=d
              )
      elif mode == "valid":
          # TODO: we do not implement all mode with this code.
          # Add a check for the good cases.
          output_4d = output_2d.reshape(original_shape, ndim=4)
      else:
          raise NotImplementedError(
              "neibs2images do not support mode=%s" % mode
          )
  
      return output_4d
  
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import theano
  from theano import Op, Apply
  from theano.gof import EnumList
  import theano.tensor
  from theano.gradient import grad_not_implemented
  from theano.gradient import grad_undefined
label_desc: Use image node_id 2 for calling a global function with example usage: neibs2images(neibs, neib_shape, original_shape, mode) and returns: output_4d