Cosine Similarity Calculator

Enter two vectors of the same length to find the cosine of the angle between them.

Write the numbers in brackets, like (1, 2, 3). Both vectors need the same length.

Write the numbers in brackets, like (4, 5, 6).

Try

Result

You enteredcos⁡θ for (1,2,3) and (4,5,6)\cos\theta \text{ for } \left(1, 2, 3\right) \text{ and } \left(4, 5, 6\right)

≈0.974632\displaystyle \approx 0.974632

Rounded to 6 decimal places.

Exact value

162277\displaystyle \frac{16\sqrt{22}}{77}

Angle between the vectors

12.933154∘\displaystyle 12.933154^\circ
Show the work
  1. Dot product

    Multiply the matching components of u\mathbf{u} and v\mathbf{v} and add the products.

    u⋅v=u1v1+u2v2+⋯+unvn=1×4+2×5+3×6=32\begin{aligned} \mathbf{u} \cdot \mathbf{v} &= u_1 v_1 + u_2 v_2 + \cdots + u_n v_n \\ &= 1 \times 4 + 2 \times 5 + 3 \times 6 \\ &= 32 \end{aligned}
  2. Lengths of the vectors

    The squared length of a vector is the sum of the squares of its components. Both lengths must be more than 0, or the angle between the vectors would not mean anything.

    ∣u∣2=12+22+32=14,  ∣v∣2=42+52+62=77\left|\mathbf{u}\right|^2 = 1^2 + 2^2 + 3^2 = 14,\ \ \left|\mathbf{v}\right|^2 = 4^2 + 5^2 + 6^2 = 77
  3. Cosine similarity

    The cosine of the angle θ\theta between two vectors is their dot product divided by the product of their lengths. It is 1 when they point the same way, 0 at right angles and −1-1 when they point in opposite directions.

    cos⁡θ=u⋅v∣u∣∣v∣=321477=321078≈0.974632\begin{aligned} \cos\theta &= \frac{\mathbf{u} \cdot \mathbf{v}}{\left|\mathbf{u}\right|\left|\mathbf{v}\right|} \\ &= \frac{32}{\sqrt{14}\sqrt{77}} \\ &= \frac{32}{\sqrt{1078}} \approx 0.974632 \end{aligned}
  4. Result

    So the cosine similarity is ≈0.974632\approx 0.974632.

Worked examples