Solved by jarvico in post #2 
              
              
                Update after searching on the forum, I think these solve the problems: 




outer_product = a[:, :, None] @ a[:, None, :]





solution.diagonal(dim1=-2, dim2=-1)[:]