import torch


def one_hot_tensor(idx, length):
    """ Return a one hot tensor (1xlength) with 1 at idx and 0 at other position

    Argument:
        idx (int) - such that one_hot[idx] = 1.0
        length (int) - length of the one hot tensor

    Return:
        torch.FloatTensor of size 1xlength
    """

    one_hot = torch.FloatTensor(1, length).zero_()
    one_hot[0][idx] = 1.0
    return one_hot