Created
September 6, 2017 15:41
-
-
Save codeboy101/f345e1392c57fdf05d3794a576f54aba to your computer and use it in GitHub Desktop.
This file contains 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
import numpy as np | |
def gram_schmidt(vectors): | |
q1 = vectors[0]/np.linalg.norm(vectors[0]) | |
result = [q1] | |
for b in vectors[1:]: | |
comp = b + rm_dupl_projctns(b, result) | |
result.append(comp/np.linalg.norm(comp)) | |
return np.concatenate(result, axis=1) | |
def rm_dupl_projctns(b, result): | |
total = 0 | |
for x in result: | |
total -= np.matmul(x.T, b) * x | |
return total | |
def get_projection(a, b): | |
return np.matmul(a.T, b) * a | |
a = np.array([1,2,2]).reshape(3,1) | |
b = np.array([1,3,1]).reshape(3,1) | |
#c = np.array([0,1,1]).reshape(3,1) | |
vectors = [a, b] | |
x = gram_schmidt(vectors) | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment