\(\newcommand{L}[1]{\| #1 \|}\newcommand{VL}[1]{\L{ \vec{#1} }}\newcommand{R}[1]{\operatorname{Re}\,(#1)}\newcommand{I}[1]{\operatorname{Im}\, (#1)}\)

Encoding zooms (scaling) with a diagonal matrixΒΆ

If I want to express the fact that I am expanding or contracting a coordinate along the x axis, then I multiply the x coordinate by some scalar \(p\):

\[\begin{split}\begin{bmatrix} x'\\ y'\\ z'\\ \end{bmatrix} = \begin{bmatrix} p x\\ y\\ z\\ \end{bmatrix}\end{split}\]

In general if I want to scale by \(p\) in \(x\), \(q\) in \(y\) and \(r\) in \(z\), then I could multiply each coordinate by the respective scaling:

\[\begin{split}\begin{bmatrix} x'\\ y'\\ z'\\ \end{bmatrix} = \begin{bmatrix} p x\\ q y\\ r z\\ \end{bmatrix}\end{split}\]

We can do the same thing by multiplying the coordinate by a matrix with the scaling factors on the diagonal:

\[\begin{split}\begin{bmatrix} x'\\ y'\\ z'\\ \end{bmatrix} = \begin{bmatrix} p x\\ q y\\ r z\\ \end{bmatrix} = \begin{bmatrix} p & 0 & 0 \\ 0 & q & 0 \\ 0 & 0 & r \\ \end{bmatrix} \begin{bmatrix} x\\ y\\ z\\ \end{bmatrix}\end{split}\]

You can make these zooming matrices with np.diag:

>>> import numpy as np
>>> zoom_mat = np.diag([3, 4, 5])
>>> zoom_mat
array([[3, 0, 0],
       [0, 4, 0],
       [0, 0, 5]])