Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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))
Add Comment
Please, Sign In to add comment