Home > Mobile >  "AttributeError: 'float' object has no attribute 'reshape'."
"AttributeError: 'float' object has no attribute 'reshape'."

Time:05-08

similarity matrix

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] , an error shows in this segment as AttributeError: 'float' object has no attribute 'reshape'

CodePudding user response:

This is almost impossible to answer definitely without knowing what 'sentence_vectors', 'cleaned_text' and 'sentences' are.

I can explain the error message though. It seems that you expect sentence_vectors to be a list of numpy arrays, but the error tells you that sentence_vectors[j] is a float, not a numpy array. You should probably ensure that the list is generated correctly. :)

  • Related