Change tensor of shape=(100,1) to (100, 5) applying custom Python function on each element and calculate loss on result

Hi,

I want to represent a Tensor of shape=(100,1) of floats of batch=100 to a Tensor representing list of binary encoding of each float number. Example: 10.0 → [0, 1, 0, 1, 0]… where new Tensor is again same batch where each row, which was float, is now being represented by list of encoded value

How to apply custom Python function to convert input tensor to required output here? I tried apply_ but it needs output of callable function to return a real number and not list.

tensor = tensor.apply_(encoding)

TypeError: must be real number, not list

I am trying to output list of 5 numbers(logits) where it must represent binary encoding of a positive integer value. And tried to use nn.BCEWithLogitsLoss for calculating the loss. The idea is to input preds of 100,5 and actual value of 100,1 converted to 100,5 (here each row is binary encoding of the float) to calculate loss.

Is this the correct approach or any better ways of handling this?

Thanks