How to calculate the cosine distance between two arrays in Python

1 Answer

0 votes
from scipy.spatial.distance import cosine
import numpy as np

arr1 = np.array([1, 1, 1, 0, 0, 1, 0])
arr2 = np.array([0, 1, 0, 1, 1, 0, 0])

print(cosine(arr1, arr2))




'''
run:

0.7113248654051871

'''

 



answered Mar 2, 2023 by avibootz
...