PIXELBANKv8.2.1
Menu

Cosine Similarity Calculator

Given two vectors (as comma-separated floats), compute the cosine similarity between them.

Cosine similarity measures the cosine of the angle between two vectors: cosine_similarity=ABA×B\text{cosine\_similarity} = \frac{A \cdot B}{\|A\| \times \|B\|}

Round the result to 4 decimal places.

Input format:

  • Line 1: Vector A (comma-separated floats)
  • Line 2: Vector B (comma-separated floats)

Example:

Input:
1.0,0.0,1.0
0.0,1.0,1.0
Output:
0.5
Reasoning:

Step 1: Compute dot product A·B = 1.00.0 + 0.01.0 + 1.0*1.0 = 1.0

Step 2: Compute magnitudes ||A|| = sqrt(1+0+1) = sqrt(2) ≈ 1.4142 ||B|| = sqrt(0+1+1) = sqrt(2) ≈ 1.4142

Step 3: Divide 1.0 / (1.4142 * 1.4142) = 1.0 / 2.0 = 0.5

Constraints:

  • Vectors have the same dimension
  • Output: A single float rounded to 4 decimal places
  • Vectors will not be zero vectors
Editor

Test Results

0/0
Run code to see test results.