def one_hotify(labels, pad=-1):
    """
    cast label to one hot vector
    """
    num_instances = len(labels)
    if pad <= 0:
        dim_embedding = np.max(labels) + 1  # zero-indexed assumed
    else:
        assert pad > 0, "result_dim for padding one hot embedding not set!"
        dim_embedding = pad + 1
    embeddings = np.zeros((num_instances, dim_embedding))
    embeddings[np.arange(num_instances), labels] = 1

    return embeddings

    cast label to one hot vector
    
examples/pytorch/diffpool/data_utils.py