I need to generate a tall-and-thin random column-orthonormal matrix in SciPy; that is, the number of rows n
is far greater than the number of columns of p
by many orders of magnitude (say n = 1e5
and p = 100
. I know that scipy.stats.ortho_group
generates a square orthogonal matrix. However, in my case it's simply infeasible to generate an n
-by-n
random orthogonal matrix and then keep the first p
columns... Is there a more time- and space- efficient approach?
You can first generate a tall and thin random matrix, and then perform a qr decomposition.
a = np.random.random(size=(100000, 100))
q, _ = np.linalg.qr(a)
Here q
is the matrix you want.