检索系统向量化计算query-doc相似度
1 def cal_sim2(A,B): 2 ''' 3 A :query [1,2] 4 B: answers [[1,2],[3,5]] 5 ''' 6 need_norm=False 7 A = np.array(A) 8 B = np.array(B) 9 A=A/np.linalg.norm(A) 10 if need_norm: 11 #A=A/np.linalg.norm(A) 12 B= B/np.linalg.norm(B,axis=1).reshape(B.shape[0],1) 13 14 sim = A.dot(B.T) 15 return sim