Solved by LeviViana in post #2 
              
              
                The following is the same idea, but with less code: 
import torch
x = torch.tensor([[[0.7418, 0.3182, 0.4222, 0.0584, 0.0477]],
        [[0.4293, 0.3079, 0.2928, 0.8873, 0.9470]],
        [[0.6137, 0.3592, 0.2576, 0.8944, 0.4743]],
        [[0.6279, 0.2723, 0.2599, 0.6904, 0.9212]],
        [[0.2126…