簡體   English   中英

Gensim Word2Vec model 浮點數

[英]Gensim Word2Vec model floating point

我已經使用 gensim 訓練了 word2vec model。 在模型矩陣中,一些值的浮點數如下所示:“-7.18556e-05”

我需要將矩陣上的值用作字符串。 有沒有辦法刪除那些“e-05”、“e-04”等?

import nltk
from gensim.models import Word2Vec
from nltk.corpus import stopwords

text = "My text is here"
sentences = nltk.sent_tokenize(text)
for i in range(len(sentences)):
    sentences[i] = [word for word in sentences[i] if word not in stopwords.words('english')]

model = Word2Vec(sentences, min_count=1)

words = model.wv.vocab

for word in words:
    matrix = model.wv[words.keys()]

請注意,這些科學記數法打印輸出是有效字符串,並且 Python 和許多可能在 output 上使用的讀取例程都可以理解。

而且,當為某些非常特定的目的打印時,有各種格式選項(包括注釋中提到的.format()選項)可以准確地獲得您需要的內容。 (您還沒有展示您當前使用的觸發矩陣/陣列顯示的方法,因此不清楚在關鍵 output 點上更改顯示的建議是最好的。)

而且:來自gensim和大多數類似庫的所有向量/矩陣通常由numpy提供,它具有更改顯示選項的全局設置,包括用於完全停止此類符號的suppress參數。 有關更多詳細信息,請參見其他答案:

https://stackoverflow.com/a/2891805/130288

最終,您可能不想依賴此設置,在某個特定時間和全球范圍內,在一個特定的有意位置獲得您想要的 output。 為此目的明確格式化結果會更清晰,更健壯的代碼。 但作為一種快速解決方法,以上內容可能適合您的需要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM