+3 votes
in Programming Languages by (17.9k points)
I want to compute the cosine distance between two vectors/arrays. What function should I use for it?

1 Answer

0 votes
by (31.6k points)

The cosine() function of scipy can be used to compute the cosine distance between two numpy arrays or list.

Here is an example:

>>> from scipy.spatial.distance import cosine
>>> import numpy as np
>>> a=np.array([1,0,0,1,1,0,0,0,1])
>>> b=np.array([1,0,0,1,1,0,0,1,1])
>>> cosine(a,b)
0.10557280900008414

...