def unsqueeze_to(x, total, target):
    """Unsqueezes a dimension-1 tensor to the :attr:`target` position,
    out of a total of :attr:`total` dimensions.

    Example::

        >>> x = torch.arange(5)
        >>> y = unsqueeze_to(x, 6, 2)
        >>> assert y.shape == (1, 1, 5, 1, 1, 1)

    :param torch.Tensor x:
    :param int total:
    :param int target:
    :returns:
    """
    ones = total - target - 1
    twos = target
    r = x
    for i in range(twos):
        r.unsqueeze_(-2)
    for i in range(ones):
        r.unsqueeze_(-1)
    return r