scikit-learn
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
a = [2, 15, 3, 25]
b = [5, 25, 8, 28]
array_1 = np.array([a])
array_2 = np.array([b])
cos_sim = cosine_similarity(array_1 , array_2)
print(cos_sim)
# 結果:
# [[0.9753719]]
NumPy
from numpy import dot
from numpy.linalg import norm
a = [2, 15, 3, 25]
b = [5, 25, 8, 28]
cos_sim = dot(a, b) / (norm(a) * norm(b))
print(cos_sim)
# 結果:
# 0.9753719044721808