Rewrite sum over products into matrix product

matrices

Let $n \times n$ matrix $H$ be defined by

$$H_{k,l} := \sum_{i=1}^m A_{i,k} \cdot A_{i,l} \cdot v_i$$

where matrix $A$ is $m \times n$ and column vector $\vec{v}$ is $m \times 1$. How can I rewrite this sum into a matrix product?

I want to directly calculate $H$ not $H_{k,l}$. I need to program this in Python with NumPy and want to simplify it as much as possible. That said, elementwise multiplication ($\odot$) would be fine as well.

Best Answer

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} $$

Related Question