def _two_dimensional(inp):
    """
    Given an input layer transforms its output to 2 dimensions (or if it is
    already 2 dimensions leaves it be).  Used to prepare input for
    layers that only process two dimensional input such as
    :class:`_FullyConnectedLayer`, :class:`_LogisticRegression` and
    :class:`_MergeLayer`.

    :param inp: the input layer
    :return: (transformed input, shape of transformed input)
    """
    if len(inp.out_shape) == 4:
        return inp.output.flatten(2), (inp.out_shape[0], inp.out_shape[1] *
            inp.out_shape[2] * inp.out_shape[3])
    elif len(inp.out_shape) == 2:
        return inp.output, inp.out_shape
    else:
        raise Exception(
            '{} dimensional input not supported; input must be 2 or 4 dimensions'
            .format(len(inp.out_shape)))
