# Is there a more elegant way to express $\mathbf{M}\circ(\mathbf{z}\otimes\mathbf{z}^T)$?

I want to create a square matrix from another square matrix, $\mathbf{M}$, where the values in specific rows and columns are blanked by according to a 1-dimensional matrix, $\mathbf{z}$. So for example, with

$$\mathbf{M}=\begin{bmatrix} 1 & 0.5 & 0.5 & 0.5\\ 0.5 & 1 & 0.5 & 0.5\\ 0.5 & 0.5 & 1 & 0.5 \\ 0.5 & 0.5 & 0.5 & 1 \end{bmatrix}$$ and $$\mathbf{z}=\begin{bmatrix} 1 & 1 & 0 & 0\\ \end{bmatrix}$$ I want the outcome $$\begin{bmatrix} 1 & 0.5 & 0 & 0\\ 0.5 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \end{bmatrix}$$ I think the notation $\mathbf{M}\circ(\mathbf{z}\otimes\mathbf{z}^T)$ works, but I feel like there must be a nicer way to write it, perhaps as some kind of matrix multiplication?

• You don't need to write $\otimes$ here, it's simply $\mathbf{M}\circ(\mathbf{z}\mathbf{z}^T)$ if by $\circ$ you understand component-wise multiplication (which does not have a standard notation). – amoeba Jul 19 '17 at 19:02
• (Also, I vote to migrate to Math.SE) – amoeba Jul 19 '17 at 19:04

## 1 Answer

$\mathbf{D_z M D_z}$ where $\mathbf{D_z} = \text{diag}(\mathbf{z}),$ i.e. the diagonal matrix whose diagonal elements are given by $\mathbf{z}.$ (Thanks, amoeba, for the notation.)

Right-multiplying by $\mathbf{D_z}$ gets rid of the last two columns. Left-multiplying by $\mathbf{D_z}$ gets rid of the bottom two rows.

EDIT: Here's a small proof, in case you wanted one.

Let $\mathbf{M}$ be a $k \times k$ matrix and $\mathbf{z}$ be a $k \times 1$ vector. Let $\mathbf{D} = \text{diag}(\mathbf{z}).$ Then,

$$\begin{split} (\mathbf{D M D})_{i j} &= \sum_{k,l} \mathbf{D}_{i k} \mathbf{M}_{k l} \mathbf{D}_{l j} \\ &= \sum_{k,l} \mathbf{z}_i \delta_{i k} \mathbf{M}_{k l} \delta_{l j} \mathbf{z}_j \\ &= \mathbf{M}_{i j} \mathbf{z}_i \mathbf{z}_j = \left[\mathbf{M} \circ (\mathbf{z z^T})\right]_{i j} \end{split}$$ for all $i,j.$ Therefore $\mathbf{D M D} = \mathbf{M} \circ (\mathbf{z z^T}).$

• +1. One could write $\mathbf{D_z}$ as $\operatorname{diag}(\mathbf z)$. – amoeba Jul 19 '17 at 20:11
• Excellent, thank you. – sammosummo Jul 19 '17 at 23:22