Rewrite sum over products into matrix product

Let $\mathbf{B}=\mathrm{diag}(\mathbf{v}) \mathbf{A}$. It is easy to see that $$ B_{il} = v_i A_{il} $$ From here, you will see that your are computing the symmetric matrix $$ \mathbf{A}^T \mathbf{B} = \mathbf{A}^T \mathrm{diag}(\mathbf{v}) \mathbf{A} $$