Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanekomasahiro/d8bc3e43a25b6e264c5b52318ff7ca72 to your computer and use it in GitHub Desktop.
Save kanekomasahiro/d8bc3e43a25b6e264c5b52318ff7ca72 to your computer and use it in GitHub Desktop.
numpyで行列のコサイン類似度を計算
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