Math expression for indices of non-zero values from a matrix column

175 Views Asked by At

Let the matrix $M = \begin{bmatrix}12&2&16&15\\6&8&18&0\\0&0&0&25\\3&20&0&2\end{bmatrix}$ and the matrix $J = \begin{bmatrix}22&2&6&5\\0&17&9&0\\10&0&0&5\\7&0&0&2\end{bmatrix}$

I want to write the cosine similarity formula between a vector of non-zero values of the $k$ column of $M$ and the corresponding $k$ row of $J$ at the position of non-zero values of the $k$ column of $M$.

If $k = 1$, how to write the matrix symbols for $\begin{bmatrix}22&2&5\end{bmatrix}$ and $\begin{bmatrix}12&6&3\\\end{bmatrix}^T$ for using in cosine similarity formula as

$\frac{\begin{bmatrix}22&2&5\end{bmatrix} \begin{bmatrix}12&6&3\end{bmatrix}^T}{\lVert\begin{bmatrix}22&2&5\end{bmatrix}\rVert\lVert\begin{bmatrix}12&6&3\end{bmatrix}^T\rVert}$?

(Here are J 1st row at the position [1,2,4] with M 1st column at the position [1,2,4]. The position [1,2,4] comes from non-zero positions of M 1st column)

If $k = 2$, it is $\begin{bmatrix}0&17&0\\\end{bmatrix} \begin{bmatrix}2&8&20\end{bmatrix}^T$

(Here are J 2nd row at the position [1,2,4] and M 2nd column at the position [1,2,4]. Again, the position [1,2,4] comes from non-zero positions of M 2nd column)

If $k = 3$, it is $\begin{bmatrix}10&0\end{bmatrix} \begin{bmatrix}16&18\end{bmatrix}^T$

(J 3rd row at the position [1,2] is with M 3rd column at the position [1,2] because now only at the positions [1,2] of M 3rd column are non-zero)

Can I describe them as

"calculate the cosine similarity between $J_{kg}$ and $M^T_{gt}$ where $g$ was a vector of positions of non-zero values of $M$"?