相似矩陣
sim_mat = np.zeros([len(cleaned_texts), len(cleaned_texts)])
for i in range(len(sentences)):
for j in range(len(sentences)):
if i != j:
sim_mat[i][j] = cosine_similarity(sentence_vectors[i].reshape(1, dim),
sentence_vectors[j].reshape(1, dim))[0, 0]
sim_mat = np.round(sim_mat, 3)
# print(sim_mat)
-- sentence_vectors[j].reshape(1, dim))[0, 0] ,錯誤在此段中顯示為 AttributeError: 'float' object has no attribute 'reshape'
uj5u.com熱心網友回復:
在不知道“sentence_vectors”、“cleaned_text”和“sentences”是什么的情況下,這幾乎是不可能明確回答的。
我可以解釋錯誤資訊。您似乎希望sentence_vectors是一個 numpy 陣列串列,但錯誤告訴您sentence_vectors[j]是一個浮點數,而不是一個 numpy 陣列。您可能應該確保正確生成串列。:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/469990.html
下一篇:如何迭代索引物件陣列