A question on updating x variable in dinosaur assignment

In the ‘sample’ function implementation, the input x:

x = np.zeros((vocab_size, 1))

then in the while loop:

while (idx != newline_character and counter != 50):

   ....
    y = softmax(z)
    x = np.zeros(y.shape)
   ...

In each iteration, y’s shape is always [27,1], so the “x = np.zeros(y.shape)” should be always of zeros of [27, 1], which is the same as the x’s initialization outside of the while loop. So I thought I don’t really need the “x = np.zeros(y.shape)” line inside the loop, because it will result in the same x as the ‘x’ outside of the loop. However, if I comment out this assignment line, it reports an error.

What’s wrong with my understanding?

Well, think about what is really happening in that loop there. The result is that x ends up being a “one hot” vector specifying one letter (the next letter in the new name), right? So what happens if you don’t zero it every time around the loop? If thinking about it isn’t enough to see the point, then try printing the results and watch what happens without that np.zeros call in the loop.

Oh yes, I should also read the next line, which turns all zeros into a one-hot vector, in which 1 exists in the vector.