1
$\begingroup$

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?

$\endgroup$
2
  • 1
    $\begingroup$ 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). $\endgroup$ – amoeba Jul 19 '17 at 19:02
  • 1
    $\begingroup$ (Also, I vote to migrate to Math.SE) $\endgroup$ – amoeba Jul 19 '17 at 19:04
3
$\begingroup$

$\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}).$

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.