What you are searching for is cosine_similarity from sklearn library.
Here is a simple example:
Lets we have x
which has 5 dimensional 3 vectors and y
which has only 1 vector. We can compute cosine similarity as follows:
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
x = np.random.rand(3,5)
y = np.random.rand(1,5)
# >>> x
# array([[0.21668023, 0.05705532, 0.6391782 , 0.97990692, 0.90601101],
# [0.82725409, 0.30221347, 0.98101159, 0.13982621, 0.88490538],
# [0.09895812, 0.19948788, 0.12710054, 0.61409403, 0.56001643]])
# >>> y
# array([[0.70531146, 0.10222257, 0.6027328 , 0.87662291, 0.27053804]])
cosine_similarity(x, y)
Then the output is the cosine similarity of each vector from x
(3) with y
(1) so the output has 3x1
values:
array([[0.84139047],
[0.75146312],
[0.75255157]])