Skip to content

Instantly share code, notes, and snippets.

@galenseilis
Last active October 16, 2022 06:43
Show Gist options
  • Select an option

  • Save galenseilis/0324f50edbc096f0cb84430acdee666a to your computer and use it in GitHub Desktop.

Select an option

Save galenseilis/0324f50edbc096f0cb84430acdee666a to your computer and use it in GitHub Desktop.
import os.path as path
from tempfile import mkdtemp
import numpy as np
m = 10**6
n = 10**3
filename = path.join(mkdtemp(), 'X.dat')
X = np.memmap(filename, dtype='float32', mode='w+', shape=(m, n))
for k in range(n):
print(k)
X[:,k] = np.random.normal(size=m)
beta = np.random.normal(size=n)
y = np.sum(beta * X, axis=1)
beta_hat = np.matmul(np.linalg.pinv(np.matmul(X.T, X)), X.T) @ y
print(np.all(np.isfinite(beta_hat)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment