How to use this calculator
Compare vector direction independently of overall magnitude using cosine similarity.
- Enter First vector, Second vector. Match the units shown beside each field and review the result together with the assumptions below.
- Read the worked example below to check the expected input format and result.
- Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Cosine vector similarity explained
How the calculation works
h.dot(a,b)/(h.norm(a)*h.norm(b))
Equal-dimensional nonzero vectors; the result is not generally a metric distance..
Set up the calculation
a— First vector- First vector as comma-separated components in feature order. It must be nonzero and have the same number of components as the second vector.
b— Second vector- Second vector in the same feature order and dimension as the first. The cosine compares direction, so positive rescaling alone does not change the score.
Limits of this model
Equal-dimensional nonzero vectors; the result is not generally a metric distance.
Check this example
First vector = 1, 2, 3; Second vector = 2, 0, 1.
- Cosine similarity: 0.5976143
An orthogonal-vector check
For vectors (1, 0, 0) and (0, 1, 0), the dot product is zero, so cosine similarity is 0. Their directions are perpendicular even though both vectors are nonzero.
Reading the outputs
A score of 1 means the vectors point in the same direction, 0 means they are orthogonal, and −1 means they point in opposite directions. For nonnegative feature vectors, the possible scores are 0 through 1.
Frequently asked questions
Can similarity be negative?
Yes, for vectors pointing in opposing directions.
What if a vector is zero?
Its direction is undefined and the input is rejected.
Does rescaling change it?
Positive scaling leaves cosine similarity unchanged.
How do I use the Cosine vector similarity calculator?
Enter First vector, Second vector. Match the units shown beside each field and review the result together with the assumptions below.
What is a worked example of Cosine vector similarity?
First vector = 1, 2, 3; Second vector = 2, 0, 1. Cosine similarity: 0.5976143
Method reference: scikit-learn cosine similarity definition. The normalized dot-product definition matches the calculator’s equal-dimension cosine score.
Read our calculation methodology.