Skip to content

Instantly share code, notes, and snippets.

@marmakoide
Created April 27, 2023 07:54
Show Gist options
  • Save marmakoide/d582c15c4586eb4e9e845d27e514a98f to your computer and use it in GitHub Desktop.
Save marmakoide/d582c15c4586eb4e9e845d27e514a98f to your computer and use it in GitHub Desktop.
Build an orthogonal projection that projects vectors on U's subspace
import numpy
def get_orthogonal_projection(U):
M = numpy.random.randn(U.shape[1], U.shape[1])
M[:U.shape[0]] = U
Q, R = numpy.linalg.qr(M.T)
M[U.shape[0]:] = Q.T[U.shape[0]:]
Q, R = numpy.linalg.qr(M.T)
return Q.T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment