How do I partition a matrix into blocks and replace zeros with dots?

Doing a “search and replace” would not be a big problem, but if there's a dirty trick available…

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{equation}
W =  \left(\mathcode`0=\cdot
\begin{array}{ *{3}{c} | *{3}{c} | *{3}{c} }
   1 & 0 & 0 & 0 & -1 & 0 & 0 & 0 & -1 \\
   0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
   0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\hline
   0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\
   -1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & -1 \\
   0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \hline
   0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
   0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\
   -1 & 0 & 0 & 0 & -1 & 0 & 0 & 0 & 1 \\
  \end{array}
\right)
\end{equation}
\end{document}

enter image description here

For the duration of the group initiate by \left(, I'm telling TeX that 0 in math mode (that is, in every cell) should be interpreted as \cdot.


You can use string replacement within LaTeX (xstring and collcell packages). For the blocks, I use dashed lines from arydshln (: in header and \hdashline in rows).

\documentclass{article}
\usepackage{array,arydshln}
\usepackage{xstring,collcell}

\newcommand{\ToDot}[1]{\StrSubstitute{#1}{0}{\cdot}}

\begin{document}
\begin{equation} 
W =  \left(
\begin{array}{ *{3}{>{\collectcell\ToDot}c<{\endcollectcell}} : 
  *{3}{>{\collectcell\ToDot}c<{\endcollectcell}} : 
  *{3}{>{\collectcell\ToDot}c<{\endcollectcell}}}
   1 & 0 & 0 & 0 & -1 & 0 & 0 & 0 & -1 \\
   0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
   0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\hdashline
   0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\
   -1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & -1 \\
   0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \hdashline
   0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
   0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\
   -1 & 0 & 0 & 0 & -1 & 0 & 0 & 0 & 1 \\
  \end{array}
\right)   
\end{equation}
\end{document}

enter image description here