# Week 1 Dinosaurus Island rnn_forward throws error

My optimize functions passes all tests. However, when I call optimize from the model function, the supplied function rnn_forward throws this error:
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

Thanks.

P.S. I already validated that my X is a list of characters, with ‘None’ in the first position, and my Y is an equal-length list of numbers with 0 in the last position. This is what I understood the instructions to intend.

X uses [None] and single_example_ix
Y is a copy of X starting from position 1, then with ix_newline appended.

Thanks–that change makes my code run, but I still get wrong values. Any clue what it could be?

Also, the directions are confusing to me–they explicitly state that X is a list of CHARACTERS, not integers, as seems to be correct:

##### Create the list of input characters: X
• rnn_forward uses the None value as a flag to set the input vector as a zero-vector.
• Prepend the list [ None ] in front of the list of input characters.
• There is more than one way to prepend a value to a list. One way is to add two lists together: ['a'] + ['b']

That probably should say “Create the list of input character indices: X”.

The previous step - Convert list of characters to a list of integers: single_example_ix
converts the characters into character indices.

The the “X” values are character indices, not the original characters. That’s what “list of integers” means.

Thank you very much for the hint. I had exactly the same error. After I correct the code accordingly, I still get the following error, could you please help me? Thank you very much!

----> 1 parameters, last_name = model(data.split("\n"), ix_to_char, char_to_ix, 22001, verbose = True)
2
3 assert last_name == ‘Trodonosaurus\n’, “Wrong expected output”
4 print("\033[92mAll tests passed!")

in model(data_x, ix_to_char, char_to_ix, num_iterations, n_a, dino_names, vocab_size, verbose)
84 if j % 2000 == 0:
85
—> 86 print('Iteration: %d, Loss: f' (j, loss) + ‘\n’)
87
88 # The number of dinosaur names to print

TypeError: only size-1 arrays can be converted to Python scalars

for debug purpose I printed the following labels:
j = 0 idx = 0
single_example = turiasaurus
single_example_chars [‘t’, ‘u’, ‘r’, ‘i’, ‘a’, ‘s’, ‘a’, ‘u’, ‘r’, ‘u’, ‘s’]
single_example_ix [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]
X = [None, [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]]
Y = [[20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19], 0]