Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def gs_cofficient(v1, v2):
- return np.dot(v2, v1) / np.dot(v1, v1)
- def multiply(cofficient, v):
- return map((lambda x : x * cofficient), v)
- def proj(v1, v2):
- return multiply(gs_cofficient(v1, v2) , v1)
- def gs(X):
- Y = []
- for i in range(len(X)):
- temp_vec = X[i]
- for inY in Y :
- proj_vec = proj(inY, X[i])
- temp_vec = map(lambda x, y : x - y, temp_vec, proj_vec)
- Y.append(temp_vec)
- return Y
- #Test data
- test = np.array([[3.0, 1.0], [2.0, 2.0]])
- test2 = np.array([[1.0, 1.0, 0.0], [1.0, 3.0, 1.0], [2.0, -1.0, 1.0]])
- print np.array(gs(test))
- print np.array(gs(test2))
Add Comment
Please, Sign In to add comment