Guest User

Untitled

a guest
Nov 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. # Python Script I wrote to perform the gram schmidt process on a set of vectors
  2. import numpy as np
  3.  
  4. def get_inverse_mag_prod(v):
  5. return v * (1 / (sum(list(map(lambda a: a ** 2,v))) ** 0.5))
  6.  
  7. def rounder(v):
  8. return list(map(lambda a: round(a,6),v))
  9.  
  10.  
  11. def gs(v):
  12. vectors = list(map(lambda a: np.array(a,dtype=np.float32),v))
  13. for vector_index in range(0,len(vectors)):
  14. current_index = vector_index
  15. v = vectors[vector_index]
  16. total = vectors[vector_index]
  17. current_index = vector_index
  18. while current_index != 0:
  19. q = vectors[current_index - 1]
  20. total -= np.dot(v,q) * q
  21. current_index -= 1
  22. vectors[vector_index] = total
  23. vectors[vector_index] = get_inverse_mag_prod(vectors[vector_index])
  24. return list(map(rounder,vectors))
  25.  
  26. x = [1,0,1]
  27. y = [0,1,-6]
  28.  
  29. my_vectors = [x,y]
  30.  
  31. print(gs(my_vectors))
Add Comment
Please, Sign In to add comment