Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"AttributeError: 'float' object has no attribute 'reshape'."

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’

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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. 🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading