【发布时间】:2016-11-28 21:49:18
【问题描述】:
以下是我的代码:
word_centroid_map =dict(zip(model.index2word, idx ))
for cluster in range(0,10):
# Print the cluster number
print ("\nCluster %d" % cluster)
# Find all of the words for that cluster number, and print them out
words = []
for i in range(0,len(word_centroid_map.values())):
if( word_centroid_map.values()[i] == cluster ):
words.append(word_centroid_map.keys()[i])
print (words)
我正在使用 python 3,我收到一条错误消息:
TypeError: 'dict_values' object does not support indexing
有人可以帮忙吗?提前致谢。
【问题讨论】:
-
看起来您正试图在 Python 3 上运行(非常低效)Python 2 代码。
-
如果您必须通过值搜索来获取感兴趣的键,这可能表明您的 dict 键控方式错误。
标签: python linguistics