Solved by ptrblck in post #6 
              
              
                Probably I misunderstood your use case. I thought you wanted to sample using the probabilities. 
In case you just want to keep the two channels with the highest probabilities, you could use a mask or slice the input. This depends on your current use case. 
batch_size = 1
c, h, w = 4, 5, 5
x = torch.…