Solved by ptrblck in post #2 
              
              
                You could use torch.multinomial to sample using weights: 
x = torch.tensor([0, 1])
weights = torch.tensor([0.5, 0.5])
idx = torch.multinomial(weights, num_samples=100, replacement=True)
out = x[idx]

Note that the indexing is not really necessary here, since the indices are already the target output…