Solved by ptrblck in post #2 
              
              
                You could use broadcasting for the first operation and sum(1) for the second one as seen here: 
# setup
mask_ref = torch.randn(125)
dots_ref = torch.randn(100, 125)

# loop approach
mask = mask_ref.clone()
dots = dots_ref.clone()

for i in range(125):
    for j in range(100):
        dots[j, i] = do…