---
jupyter:
  jupytext:
    text_representation:
      extension: .Rmd
      format_name: rmarkdown
      format_version: '1.2'
      jupytext_version: 1.11.5
  kernelspec:
    display_name: Python 3 (ipykernel)
    language: python
    name: python3
---

# 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{bmatrix}
x'\\
y'\\
z'\\
\end{bmatrix} =
\begin{bmatrix}
p x\\
y\\
z\\
\end{bmatrix}
$$

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{bmatrix}
x'\\
y'\\
z'\\
\end{bmatrix} =
\begin{bmatrix}
p x\\
q y\\
r z\\
\end{bmatrix}
$$

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

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

You can make these zooming matrices with np.diag:

```{python}
import numpy as np
zoom_mat = np.diag([3, 4, 5])
zoom_mat
```
