Cosine Similarity
subhabangalore at gmail.com
subhabangalore at gmail.com
Fri Dec 7 11:38:15 EST 2012
T
On Friday, December 7, 2012 9:47:46 AM UTC+5:30, Miki Tebeka wrote:
> On Thursday, December 6, 2012 2:15:53 PM UTC-8, subhaba... at gmail.com wrote:
>
> > I am looking for some example of implementing Cosine similarity in python. I searched for hours but could not help much. NLTK seems to have a module but did not find examples.
>
> Should be easy with numpy:
>
> import numpy as np
>
>
>
> def cos(v1, v2):
>
> return np.dot(v1, v2) / (np.sqrt(np.dot(v1, v1)) * np.sqrt(np.dot(v2, v2)))
>
>
>
>
>
> HTH,
>
> --
>
> Miki
Thanks Miki. It worked. Regards,Subhabrata.
More information about the Python-list
mailing list