# Convert Equation to Matrix Form

I have the following equation which I cannot seem to figure out how to convert to matrix form (such that I can compute it efficiently in code).

$\Sigma_m = \sum_i r_{im}(x_i - \mu_m)(x_i-\mu_m)^T$

Where $x_i$ and $\mu_m$ are vectors.

I am pretty sure that $\sum_i(x_i - \mu_m)(x_i-\mu_m)^T = ZZ^T$ where $Z$ is the matrix whose $i^{th}$ row is $x_i - \mu_m$. But I'm not sure how to incorporate the $r_{im}$ term

• Is $x_i$ a row or column vector?
– mvw
Jan 15, 2016 at 5:03
• its a column vector. so the result should be a matrix. Jan 15, 2016 at 5:59

Setting $d_{i,m} = x_i - \mu_m$ for the $N$ difference vectors then $$\Sigma_m = \sum_{i=1}^N r_{im} d_{i,m} \, d_{i,m}^T$$ If $x_i$ is a row vector, then this is a weighted sum of the $N$ scalar products $d_{i,m}\, d_{i,m}^T = \lVert d_{i,m} \rVert^2$, with weights $r_{im}$. Thus a number.

If $x_i$ is a column vector, then $d_{i,m} \, d_{i,m}^T$ is the matrix $Z_{i,m} = (z_{jk})$ with $$z_{jk} = (d_{i,m})_j \, (d_{i,m})_k$$ and $\Sigma_\mu$ is the weighted sum of those $N$ matrices $Z_{i,m}$, with weights $r_{im}$. This is a matrix.

• Right. This is what I thought initially, but I had hoped there was a way to express the weighted sum of the $N$ matrices as some kind of concise matrix/vector product or something. I suppose this is not possible. Jan 15, 2016 at 5:58
• Thanks for clarifying. Hm. Let me think.
– mvw
Jan 15, 2016 at 6:02
• It is not your suggested matrix. That one would contain vectors $d_{i,m}$ for different $i$. While the ones showing up, in the matrices which I named $Z_{i,m}$ use only the $d_{i,m}$ for one particular index $i$.
– mvw
Jan 15, 2016 at 6:06
• Out of the box, for optimization I see no more than symmetry $z_{jk} = z_{kj}$.
– mvw
Jan 15, 2016 at 6:08

As far as, I can see, your term $r_{im}$ will be multiplied with each entry of the $i^{th}$ row for a particular value of {m}. You can also say that it is embedded with each of the term.