Explore Library
Code QuizIntermediate

Cosine Similarity Missing Sqrt

Find the magnitude computation error in this cosine similarity.

Codepython
import math

def cosine(a, b):
    dot = sum(x * y for x, y in zip(a, b))
    mag_a = sum(x * x for x in a)
    mag_b = sum(y * y for y in b)
    return dot / (mag_a * mag_b)

print(cosine([1, 0], [1, 1]))

What is the bug in this cosine similarity function?