Windows XP,Python 2.5:
hash('http://stackoverflow.com') Result: 1934711907
Run Code Online (Sandbox Code Playgroud)
Google App Engine(http://shell.appspot.com/):
hash('http://stackoverflow.com') Result: -5768830964305142685
Run Code Online (Sandbox Code Playgroud)
这是为什么?我怎样才能有一个哈希函数,它可以在不同平台(Windows,Linux,Mac)上提供相同的结果?
我相信hash()所有python解释器中的函数都是一样的.但是当我使用python for android在我的手机上运行它时它会有所不同.我得到哈希字符串和数字的哈希值相同,但是当我对内置数据类型进行哈希时,哈希值会有所不同.
PC Python解释器(Python 2.7.3)
>>> hash(int)
31585118
>>> hash("hello sl4a")
1532079858
>>> hash(101)
101
Run Code Online (Sandbox Code Playgroud)
移动Python解释器(Python 2.6.2)
>>> hash(int)
-2146549248
>>> hash("hello sl4a")
1532079858
>>> hash(101)
101
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我这是一个错误还是我误解了一些东西.
我正在使用python gensim从231个句子的小型语料库中训练潜在Dirichlet分配(LDA)模型.但是,每次重复该过程时,它都会生成不同的主题.
为什么相同的LDA参数和语料库每次都会生成不同的主题?
我如何稳定主题生成?
我正在使用这个语料库(http://pastebin.com/WptkKVF0)和这个停用词列表(http://pastebin.com/LL7dqLcj),这是我的代码:
from gensim import corpora, models, similarities
from gensim.models import hdpmodel, ldamodel
from itertools import izip
from collections import defaultdict
import codecs, os, glob, math
stopwords = [i.strip() for i in codecs.open('stopmild','r','utf8').readlines() if i[0] != "#" and i != ""]
def generateTopics(corpus, dictionary):
# Build LDA model using the above corpus
lda = ldamodel.LdaModel(corpus, id2word=dictionary, num_topics=50)
corpus_lda = lda[corpus]
# Group topics with similar words together.
tops = set(lda.show_topics(50))
top_clusters = …Run Code Online (Sandbox Code Playgroud) 我目前正在使用hash整数和字符串元组(以及整数和字符串的嵌套元组等)来计算某些对象的唯一性.除非可能存在哈希冲突,我想 - hash这些数据类型的函数是否保证为不同版本的Python返回相同的结果?
我正在练习元组哈希.在那里,我正在研究Python 2.7.以下是代码:
num = int(raw_input())
num_list = [int(x) for x in raw_input().split()]
print(hash(tuple(num_list)))
Run Code Online (Sandbox Code Playgroud)
上面的代码导致了
>>> 2
>>> 1 2
>>> 3713081631934410656
Run Code Online (Sandbox Code Playgroud)
但在我使用Python 3.4的本地PC上,答案是
>>> 1299869600
Run Code Online (Sandbox Code Playgroud)
代码被接受但我无法找出导致不同结果的原因.这是针对不同版本的Python吗?