Created
March 27, 2021 07:28
-
-
Save kanekomasahiro/d8bc3e43a25b6e264c5b52318ff7ca72 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_matrix_cosine_similarity(matrix1, matrix2): | |
return np.dot(matrix1, matrix2.T) / (np.linalg.norm(matrix1, axis=1) * np.linalg.norm(matrix2, axis=1)).reshape(-1, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment