Solved by kfxw in post #2 
              
              
                Hi, 
I think you can construct a transformation matrix, and use a matrix multiplication to implement it. I can show you an example of how to insert 0 in rows and columns. Suppose your K=2, weights are ‘A, B, C, D’, the transformations are like (hopefully you can get my point) 
 [c5f4a304da01aae02937…