# Course 5 Week 2 A2 sentences_to_indices problem

Hi,

Could you please give any hints about what is causing this error in the sentences_to_indices (I am getting this error in the third iteration of the loop when w = deep)

IndexError Traceback (most recent call last)
in
20 print("\033[92mAll tests passed!")
21
—> 22 sentences_to_indices_test(sentences_to_indices)

in sentences_to_indices_test(target)
9 max_len = 4
10 sentences = np.array([“I like deep learning”, “deep ´0.= love machine”, “machine learning smile”]);
—> 11 indexes = target(sentences, word_to_index, max_len)
12 print(indexes)
13

in sentences_to_indices(X, word_to_index, max_len)
37 # Set the (i,j)th entry of X_indices to the index of the correct word.
38 #print(list(m,word_to_index.keys()).index(‘deep’) )
—> 39 X_indices[i, j] = list(word_to_index.keys()).index(w)
40 # Increment j to j + 1
41 j = j+1

IndexError: index 1 is out of bounds for axis 1 with size 1

Thanks,
Suprio

2 Likes

But I am still getting the error:

in sentences_to_indices(X, word_to_index, max_len)
36 if w in word_to_index:
37 # Set the (i,j)th entry of X_indices to the index of the correct word.
—> 38 X_indices[i, j] = word_to_index[w]
39 # Increment j to j + 1
40 j = j+1

IndexError: index 1 is out of bounds for axis 1 with size 1

Please send me your code for that entire function via a private message.

Hi,
I have sent you the code
but not seeing any sent folder here, so please let me know if you did not receive it.

Thanks much!
Suprio

This is the key error, if your initial zeros values for X_indices is the wrong shape.