天天看點

cos_sim的詳細計算過程

@[Tcos_sim的詳細計算過程

$$`cos_sim的詳細過程

x1 = np.arange(4).reshape(2,2).astype('float32')
x2 = np.arange(1,5).reshape(2,2).astype('float32')
w12 = np.sum(x1 * x2, axis=1)
w1 = np.sum(x1 * x1, axis=1)
w2 = np.sum(x2 * x2, axis=1)
eps=1e(-8)
n12 = np.sqrt(np.clip(w1 * w2, eps * eps, None))
cos_sim = w12 / n12
           

`[array([[0.8944272],

[0.9984604]], dtype=float32)]