[('3604', 0.7113370895385742),
('63', 0.6787939071655273),
('6566', 0.6688929796218872),
('6406', 0.6664271354675293),
('15', 0.6614164113998413)]
我想获取第一个实例的索引,即:
[(log[3604], 0.7113370895385742),
(log[63], 0.6787939071655273),
(log[6566], 0.6688929796218872),
(log[6406], 0.6664271354675293),
(log[15], 0.6614164113998413)]
到目前为止,我正在这样做:
new_sentence = "My Order".split(" ")
sen2vec.docvecs.most_similar(positive=[sen2vec.infer_vector(new_sentence)],topn=5)
获取列表。任何建议将有所帮助!
答案 0 :(得分:4)
您可以使用以下列表理解:
l = [('3604', 0.7113370895385742),
('63', 0.6787939071655273),
('6566', 0.6688929796218872),
('6406', 0.6664271354675293),
('15', 0.6614164113998413)]
print([(log[int(i)], n) for i, n in l])
答案 1 :(得分:0)
我猜您有一个希望通过索引访问的名为log的对象。
如果是这种情况,这不是这样做的方法吗?
a =[('3604', 0.7113370895385742),
('63', 0.6787939071655273),
('6566', 0.6688929796218872),
('6406', 0.6664271354675293),
('15', 0.6614164113998413)]
log = range(10000)
b = [(log[int(x[0])], x[1]) for x in a]
print b