Last active
March 28, 2021 06:42
-
-
Save kanekomasahiro/198cdc20ab7930ccd9ca26d84a0bc2f6 to your computer and use it in GitHub Desktop.
numpyでベクトルのコサイン類似度を計算する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def calculate_vector_cosine_similarity(vector1, vector2): | |
return np.dot(vector1, vector2) / (np.linalg.norm(vector1) * np.linalg.norm(vector2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment