I always struggle when trying to convert vectors to matrices. Example Analytic solution for matrix factorization using alternating least squares
$$\begin{align}\frac{\partial C}{\partial x_u} &= -2\sum_ic_{ui}(p_{ui}-\color{red}{x_u^Ty_i})y_i+2\lambda x_u\\&=-2\sum_ic_{ui}(p_{ui}-\color{red}{y_i^Tx_u})y_i+2\lambda x_u\\&=-2Y^TC^up(u)+2Y^TC^uYx_u+2\lambda x_u \text{ Eq.(1)}\end{align}$$ where each row of matrix $Y\in \mathbb{R}^{n\times f}$ is $y_i^T$, the diagonal matrix $C^u\in\mathbb{R^{n\times n}}$ has coefficient $c_{ui}$ in row/column $i$, and vector $p(u)\in\mathbb{R^n}$ contains element $p_{ui}$ in row $i$.
How do I get the 3rd line from the 2nd line ? Is there a cheat sheet I can refer to or a video or a book or paper that I can read that will tell me the tips and tricks of upgrading a vector to a matrix ??????????? I am stupid and this is extremely important SO PLEASE HELP ME.
You can apply the following three facts:
Apply the first fact to $a_i=c_{ui}(p_{ui}-\color{red}{x_u^Ty_i})=c_{ui}\cdot (p_{ui}-y_i^Tx_u)$, the second one to $q_i=p_{ui}-y_i^Tx_u$ etc