import torch


def one_hot_to_dense(one_hot_labels):
    """
    converts a matrix of one-hot labels to a list of dense labels
    Inputs:
        one_hot_labels: one-hot torch tensor of shape [num_labels, num_classes]
    Outputs:
        dense_labels: 1D torch tensor array of labels
            The integer value indicates the class and 0 is assumed to be a class.
            The integer class also indicates the index for the corresponding one-hot representation
    """
    num_labels, num_classes = one_hot_labels.shape
    dense_labels = torch.zeros(num_labels)
    for label_id in range(num_labels):
        dense_labels[label_id] = torch.nonzero(one_hot_labels[label_id, :] == 1)
    return dense_labels