Skip to content

Instantly share code, notes, and snippets.

@pqlx
Created December 27, 2020 16:19
Show Gist options
  • Save pqlx/3a50c0acad68a42d62b94a053be0073b to your computer and use it in GitHub Desktop.
Save pqlx/3a50c0acad68a42d62b94a053be0073b to your computer and use it in GitHub Desktop.
Gram-Schmidt algorithm for finding orthogonal basis U in vector space Φ, given a basis V in vector space Φ
import numpy as np
def proj(u, v):
return np.multiply(u, (np.inner(u, v)/np.inner(u, u)))
def orthogonal_basis(*V):
"""Uses the Gram-Schmidt algorithm for finding an orthogonal basis of V"""
U = [None] * len(V)
for k in range(len(V)):
U[k] = V[k] - sum(proj(U([j], V[k]) for j in range(k))
return U
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment