Python 循环每个元素并基于该元素打印word2vec向量
我想使用gensim word2vec打印单词的每个向量 这是我的密码:Python 循环每个元素并基于该元素打印word2vec向量,python,printing,word2vec,Python,Printing,Word2vec,我想使用gensim word2vec打印单词的每个向量 这是我的密码: from gensim.models.word2vec import Word2Vec a = [["man", "eater", "king"]] model = Word2Vec(a, size =100, window=1, min_count=1) model.build_vocab(a, update=True) model.train(a, total_examples=1, epochs=1) """ I
from gensim.models.word2vec import Word2Vec
a = [["man", "eater", "king"]]
model = Word2Vec(a, size =100, window=1, min_count=1)
model.build_vocab(a, update=True)
model.train(a, total_examples=1, epochs=1)
""" I know that I could use:
for x in a:
print(model.wv[x])
This is not I intended because I wanted to know whether is there a possibility
to loop each element in a list and return it into the model.wv[element] by printing
every each element by using only 1 line of code"""
#For example my intended way
print(model.wv[x for x in a])
然而,这是一个综合的方法,它不会工作。我也试过了
print(model.wv[lambda x:x, a])
但还是不行。谁能告诉我如何打印每个单词向量
不使用for循环方式?我只希望打印部分是1行。
如果还不清楚,请告诉我 是的,您可以在此处使用列表理解,但不能使用您描述的格式:
[print(model.wv[x])for x in a]
非常感谢。我没有意识到我可以这样使用它。这对我来说真是又一次学习。