Cosine similarity

Write codeEasy15 minOpenAI and Anthropic style

Your task

Implement cosine similarity between two equal-length numeric vectors from scratch. Cosine similarity is the dot product of the two vectors divided by the product of their L2 (Euclidean) norms. Both inputs are non-empty lists of numbers of the same length. If either vector has zero magnitude, return 0.0. Round the result to 6 decimal places.

Examples

cosine_similarity(a: list[float], b: list[float]) -> float
Example 1
Inputcosine_similarity([1, 0, 0], [1, 0, 0])
Output1