import numpy as np, matplotlib.pyplot as plt
from sklearn.datasets import load_digits
d = load_digits()
X = d.data - d.data.mean(0) # 1797 images, 64-D (8x8)
U, S, Vt = np.linalg.svd(X, full_matrices=False) # linear AE optimum = PCA
Z = X @ Vt[:2].T # 2-D bottleneck code
plt.figure(figsize=(5.2, 3.0))
sc = plt.scatter(Z[:, 0], Z[:, 1], c=d.target, cmap="tab10", s=8, alpha=0.7)
plt.colorbar(sc, label="digit (never used to fit!)", ticks=range(10))
plt.xlabel("code $z_1$"); plt.ylabel("code $z_2$")
plt.title("64-D digits → 2-D code: classes self-organize"); plt.tight_layout(); plt.show()