#!/usr/bin/env python3
# Source: t5-linear-algebra.html
import numpy as np

rng = np.random.default_rng(4)
n, d, k = 200, 10_000, 1_000
P = rng.normal(size=(n, d))                  # 200 points in 10,000 dims
R = rng.normal(size=(d, k)) / np.sqrt(k)     # random Gaussian map
Q = P @ R                                    # same points in 1,000 dims

def pdist(Z):
    sq = (Z ** 2).sum(axis=1)
    D2 = sq[:, None] + sq[None, :] - 2 * Z @ Z.T
    i, j = np.triu_indices(len(Z), 1)
    return np.sqrt(np.maximum(D2[i, j], 0))

ratio = pdist(Q) / pdist(P)
print(round(ratio.min(), 3), round(ratio.max(), 3))   # all near 1
# 0.921 1.086
