Solved by ptrblck in post #10 
              
              
                It depends, what you want to achieve. 
The original mask before the unsqueeze and expand operations can be used to index x directly, which would yield: 
x = torch.ones([1, 167, 128])
batch_size, length, features = x.size()
p = 0.5
mask = torch.distributions.Bernoulli(
    probs=(1 - p)).sample((batc…