Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Cosine Similarity

Reply
Thread Tools

Cosine Similarity

 
 
subhabangalore@gmail.com
Guest
Posts: n/a
 
      12-06-2012
Dear Group,

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.

If anyone of the learned members may kindly help out.

Regards,
Subhabrata.
 
Reply With Quote
 
 
 
 
Miki Tebeka
Guest
Posts: n/a
 
      12-07-2012
On Thursday, December 6, 2012 2:15:53 PM UTC-8, subhaba...@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
 
Reply With Quote
 
 
 
 
subhabangalore@gmail.com
Guest
Posts: n/a
 
      12-07-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...@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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
function/process to generate sine and cosine wave FPGA VHDL 15 02-09-2008 02:21 PM
sine and cosine wave generation FPGA VHDL 8 01-14-2008 09:11 PM
cosine calcs Niv VHDL 9 08-16-2006 05:25 PM
having trouble with Discrete Cosine Transform program khaleel.alyasini@gmail.com C++ 1 03-24-2006 01:21 PM
Cosine algo, was Re: sqrt algo pete C Programming 108 11-05-2005 05:33 AM



Advertisments