/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def dotproduct(a,b): return sum([a[i]*b[i] for i in range(len(a))]) from math import acos #Calculates the size of a vector def veclength(a): return sum([a[i] for i in range(len(a))])**.5 #Calculates the angle between two vector def ange(a,b): dp=dotproduct(a,b) la=veclength(a) lb=veclength(b) costheta=dp/(la*lb) return acos(costheta)
Comments
