powered by
Computes the cosine of the angle between two numeric vectors. Both vectors must have equal length and non-zero Euclidean norms.
cosine_similarity(a, b, eps = 1e-12)
A scalar double value in [-1, 1] representing the cosine similarity between a and b.
[-1, 1]
a
b
Numeric vectors of equal length.
Non-negative numeric tolerance used to guard against division by zero. Defaults to 1e-12.
1e-12
cosine_similarity(c(1, 2, 3), c(1, 2, 3)) cosine_similarity(c(1, 0), c(0, 1)) cosine_similarity(c(1, 2), c(-1, -2))
Run the code above in your browser using DataLab