Created
December 9, 2018 00:54
-
-
Save rlee287/280ed5b9c96be7639ed9905d13b4099f to your computer and use it in GitHub Desktop.
Gram Schmidt process on np.ndarray vectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#DISCLAIMER: Gram-Schmidt is numerically unstable. Use np.linalg.qr if you actually need to calculate an orthonormal basis. | |
def proj(vec,u): | |
return np.dot(u,vec)/np.dot(u,u)*u | |
def gram_schmidt(*vectors): | |
retlist=list() | |
for vec in vectors: | |
vec_calc=np.copy(vec) | |
for exist_vec in retlist: | |
vec_calc=vec_calc-proj(vec,exist_vec) | |
retlist.append(vec_calc) | |
return retlist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment