def label_to_onehot(x, bits):
    """Converts a class vector (integers) to binary class matrix.
    Args:
        x: class vector to be converted into a matrix
            (integers from 0 to num_classes).
        num_classes: total number of classes.
    Returns:
        A binary matrix representation of the input. The classes axis
        is placed last.
    """
    classes = 2**bits

    result = torch.zeros((x.shape[0], classes), dtype=torch.float32)
    for i in range(x.shape[0]):
        result[i, x[i]] = 1

    output_shape = x.shape + (classes,)
    output = torch.reshape(result, output_shape)
    return output
Converts a class vector (integers) to binary class matrix.
Args:
x: class vector to be converted into a matrix
(integers from 0 to num_classes).
num_classes: total number of classes.
Returns:
A binary matrix representation of the input. The classes axis
is placed last.
utils/dsp.py