Solved by justusschock in post #2 
              
              
                I think you almost did it. 
A string compare should need almost no computational cost. If you initialize the l1_reg with zero you do not need the second if-closure which also saves a minimal amount of computation time. AFAIK there is no more efficient way to do so. 
l1_reg = 0
for name, W in net.nam…