def to_one_hot(y, n_dims=None):
    """Takes an integer vector and converts it to 1-hot matrix."""
    y_tensor = y
    y_tensor = y_tensor.type(torch.LongTensor).view(-1, 1)
    n_dims = n_dims if n_dims is not None else int(torch.max(y_tensor)) + 1
    y_one_hot = torch.zeros(y_tensor.size()[0], n_dims).scatter_(1, y_tensor, 1)
    return y_one_hot
Takes an integer vector and converts it to 1-hot matrix.
examples/reinforcement_learning/reinforce.py