import numpy as np def similarity(v1, v2): n1 = np.linalg.norm(v1) n2 = np.linalg.norm(v2) return np.dot(v1, v2) / n1 / n2