Created
November 22, 2017 06:21
-
-
Save MichaelScript/02c8fbab5d134d165d105cfc36c0cd51 to your computer and use it in GitHub Desktop.
Gram Schmidt
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
# Python Script I wrote to perform the gram schmidt process on a set of vectors | |
import numpy as np | |
def get_inverse_mag_prod(v): | |
return v * (1 / (sum(list(map(lambda a: a ** 2,v))) ** 0.5)) | |
def rounder(v): | |
return list(map(lambda a: round(a,6),v)) | |
def gs(v): | |
vectors = list(map(lambda a: np.array(a,dtype=np.float32),v)) | |
for vector_index in range(0,len(vectors)): | |
current_index = vector_index | |
v = vectors[vector_index] | |
total = vectors[vector_index] | |
current_index = vector_index | |
while current_index != 0: | |
q = vectors[current_index - 1] | |
total -= np.dot(v,q) * q | |
current_index -= 1 | |
vectors[vector_index] = total | |
vectors[vector_index] = get_inverse_mag_prod(vectors[vector_index]) | |
return list(map(rounder,vectors)) | |
x = [1,0,1] | |
y = [0,1,-6] | |
my_vectors = [x,y] | |
print(gs(my_vectors)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment