import torch


def one_hot_vector(length, index, device=torch.device('cpu')):
    """
    Create a one-hot-vector of a specific length with a 1 in the given index.
    Args:
        length: Total length of the vector.
        index:  Index of the 1 in the vector.
        device: Torch device (GPU or CPU) to load the vector to.

    Returns: Torch vector of size [1 x length] filled with zeros, and a 1 only at index, loaded to device.
    """
    vector = torch.zeros([1, length]).to(device)
    vector[0, index] = 1.
    return vector