[Tutor] regarding minhash and lsh

Alan Gauld alan.gauld at yahoo.co.uk
Mon Feb 11 05:38:30 EST 2019


On 11/02/2019 10:10, Alan Gauld via Tutor wrote:

>> def minhash(s, prime=4294967311):
>>   vec = [float('inf') for i in range(N)]
>>
>>   for val in s:
>>     if not isinstance(val, int): val = hash(val)
>>
>>     for perm_idx, perm_vals in enumerate(perms):
>>       a, b = perm_vals
>>       output = (a * val + b) % prime
>>        if vec[perm_idx] > output:
>>         vec[perm_idx] = output
>>
>>     return vec
> 
> Notice that the last if statement appears to
> be incorrectly indented. But that may just be an
> email glitch...

I just noticed that the return statement appears
to be inside the outer for loop so that loop
will only run once.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list