Back
import mathdef dotproduct(v1, v2): return sum((a*b) for a, b in zip(v1, v2))def length(v): return math.sqrt(dotproduct(v, v))def angle(v1, v2): return math.acos(dotproduct(v1, v2) / (length(v1) * length(v2)))
import math
def dotproduct(v1, v2):
return sum((a*b) for a, b in zip(v1, v2))
def length(v):
return math.sqrt(dotproduct(v, v))
def angle(v1, v2):
return math.acos(dotproduct(v1, v2) / (length(v1) * length(v2)))
Note: this will fail when the vectors have either the same or the opposite direction.
If you are a beginner and want to know more about Data Science the do check out the Data Science course
31k questions
32.8k answers
501 comments
693 users