Skip to content
C

Cosine Similarity Function

Easypython

Implement cosine_similarity(vec1, vec2) from scratch using NumPy, exactly as shown in the notes, and test it on two given vectors.

Approach: compute the dot product of the two vectors, divide by the product of their magnitudes (norms).

Input: Two lines: the two vectors, each as space-separated numbers of the same length.

Output: One line: the cosine similarity, to 4 decimal places.

Input (stdin)

Output

Run your code to see output here...