Course 5 Week 1 Assignment 2 (Dinosaurus Island)

Hello, I’m on Exercise 2, sample() function, of the Dinosaur assignment (Assignment 2).

Regarding step 4 inside the while loop:

 # Step 4: Overwrite the input x with one that corresponds to the sampled index `idx`.
 # (see additional hints above)
 x = None
 x[idx] = 1

Per the instruction, I should turn x into the one-hot vector for every iteration through the while loop. Because x was initialized to a zero vector prior to the while loop, x = np.zeros(vocab_size). Should I just need to set x[idx] = 1 ? Why do I have to overwrite the input x with one that corresponds to the sampled index idx before setting x[idx] = 1 ? That’s where I got confused ! Thanks.

But the point is you need to reinitialize x every time through the loop, right? It had a different element set to 1 last time around, so how do you deal with that? The point of “one hot” representation is that there are all zeros except for one entry with a 1, but that entry is different every time.

To put it in slightly more concrete terms: what is the value of x the second or n-th time through that loop?

2 Likes

You are absolutely right! I must have been sleepy to ask this embarrassing question! Thanks.