Python ValueError

0 votes

Hello, I am getting the error "ValueError: could not broadcast input array from shape (0,) into shape (100,)"

while trying to execute the below code. How can I resolve this?

embeddings_index = {}

embedding_dim = 100

f = 'glove.twitter.27B.100d.txt'

for line in f:

    values = line.split()

    word = values[0]

    coefs = np.asarray(values[1:], dtype='float32')

    embeddings_index[word] = coefs


print('Found %s word vectors.' % len(embeddings_index))

embedding_matrix = np.zeros((len(word_index) + 1, embedding_dim))

c = 0

for word, i in word_index.items():

    embedding_vector = embeddings_index.get(word)

    if embedding_vector is not None:

        c+=1

        embedding_matrix[i] = embedding_vector

print(c)
May 22, 2022 in Python by Ankita

edited Mar 4, 2025 309 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP