Inverse of "diagonal block" matrix Let
$$A = \begin{bmatrix} A_{11} & \cdots  & A_{1m} \\ \vdots & \ddots & \vdots \\ A_{m1} & \cdots & A_{mm} \end{bmatrix}$$ be a block matrix where each matrix $A_{ij} \in \mathbb{R}^{n\times n}$ is diagonal. What is $A^{-1}$?
It seems that it's possible to iteratively apply the usual $2 \times 2$ inverse formula. However, since that seems as though it would produce something very complicated, I'm not sure if there's a more clever way.
 A: Any matrix with diagonal blocks (assuming the blocks have the same size) can be converted to a block-diagonal matrix. In particular, suppose that $a_{ijk}$ denotes the $k$th diagonal entry of the block $A_{ij}$, so that
$$
A_{ij} = \pmatrix{a_{ij1}  \\ & \ddots \\ && a_{ijn}}.
$$
There exists a permutation matrix $P$ such that
$$
P^TAP = \pmatrix{B_1\\ & \ddots \\ && B_n},
$$
where
$$
B_k = \pmatrix{
a_{11k} & \cdots & a_{1mk}\\
\vdots & \ddots & \vdots \\
a_{m1k} & \cdots & a_{mmk}}.
$$
It follows that the inverse of $A$ (assuming it exists) satisfies
$$
A^{-1} = P\pmatrix{B_1^{-1}\\ & \ddots \\ && B_n^{-1}}P^T.
$$
In other words, $A^{-1}$ will have the block-structure
$$
A^{-1} = \pmatrix{C_{11} & \cdots & C_{1m}\\
\vdots & \ddots & \vdots\\
C_{m1} & \cdots & C_{mm}},
$$
where $C_{ij}$ is a diagonal matrix whose $k$th diagonal entry is the $i,j$ entry of $B_k^{-1}$.

If you're interested in what the matrix $P$ looks like, it can be written as
$$
P = \sum_{i,j = 1}^{m,n} (e_{i}^{(m)} \otimes e_j^{(n)})(e_j^{(n)} \otimes e_i^{(m)})^T
$$
where $e_i^{(n)}$ denotes the $i$th canonical basis vector of $\Bbb R^n$ (the $i$th column of the size $n$ identity matrix), and $\otimes$ denotes the Kronecker product.
