def back2dim(x, xdim=-1):
    """
    Transpose ndarray so that the back dimension is moved to a given position.

    Parameters
    ----------
    x : ndarray
        Input array.
    xdim : int, optional
        Dimension at which to put the back "x" input array dimension.
        (default=-1)

    Returns
    -------
    y : ndarray
        view of x transposed

    """
    num_dims_x = len(x.shape)
    if xdim < 0:
        xdim = num_dims_x + xdim
    return x.transpose(*(list(range(xdim)) + [num_dims_x-1] + \
                         list(range(xdim, num_dims_x-1))))