Linear Transformation
My learning notes.
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-10, 10, 1)
y = np.arange(-10, 10, 1)
xx, yy = np.meshgrid(x, y)
plt.scatter(xx, yy, s=30, c=xx+yy)
# [...] Add axis, x and y witht the same scale
T = np.array([
[-1, 0],
[0, -1]
])
xy = np.vstack([xx.flatten(), yy.flatten()])
xy.shape
trans = T @ xy
trans.shape
xx_transformed = trans[0].reshape(xx.shape)
yy_transformed = trans[1].reshape(yy.shape)
f, axes = plt.subplots(1, 2, figsize=(6, 3))
axes[0].scatter(xx, yy, s=10, c=xx+yy)
axes[1].scatter(xx_transformed, yy_transformed, s=10, c=xx+yy)
# [...] Add axis, x and y witht the same scale
T = np.array([
[1.3, -2.4],
[0.1, 2]
])
trans = T @ xy
xx_transformed = trans[0].reshape(xx.shape)
yy_transformed = trans[1].reshape(yy.shape)
f, axes = plt.subplots(1, 2, figsize=(6, 3))
axes[0].scatter(xx, yy, s=10, c=xx+yy)
axes[1].scatter(xx_transformed, yy_transformed, s=10, c=xx+yy)
# [...] Add axis, x and y witht the same scale
# T_inv @ T @ v = I @ v = v
T = np.array([
[1.3, -2.4],
[0.1, 2]
])
trans = T @ xy
T_inv = np.linalg.inv(T)
un_trans = T_inv @ T @ xy
f, axes = plt.subplots(1, 3, figsize=(9, 3))
axes[0].scatter(xx, yy, s=10, c=xx+yy)
axes[1].scatter(trans[0].reshape(xx.shape), trans[1].reshape(yy.shape), s=10, c=xx+yy)
axes[2].scatter(un_trans[0].reshape(xx.shape), un_trans[1].reshape(yy.shape), s=10, c=xx+yy)
# transformation by a singular matrix cannot be reset because the points
# land on each other in the same space hence non retrievable
T = np.array([
[3, 6],
[2, 4],
])
trans = T @ xy
f, axes = plt.subplots(1, 2, figsize=(6, 3))
axes[0].scatter(xx, yy, s=10, c=xx+yy)
axes[1].scatter(trans[0].reshape(xx.shape), trans[1].reshape(yy.shape), s=10, c=xx+yy)
# [...] Add axis, x and y witht the same scale