Week 1 Dinosaurus Island random.choice

Hi @MinhPham ,

Great to hear the problem is now solved. Thanks

@MinhPham: It would be good to know what the solution was.

Hi @TMosh ,

The problem was this line of code x[idx] = char_to_ix.get(idx)

Thanks for the info.

Hi @Kic and @TMosh,

Thanks very much for you help in resolving the issue.
Wish you have a great weekend.

Regards,
Minh Pham

Hi,
I was in the same situation. changed the initializations for a_prev to correct them, but still I get this error:
Wya dims:(27, 100)
a dims:(100, 1)
z dims:(27, 1)
y dims:(27, 1)
(27, 1)

TypeError Traceback (most recent call last)
in
19 print("\033[92mAll tests passed!")
20
—> 21 sample_test(sample)

in sample_test(target)
7
8
----> 9 indices = target(parameters, char_to_ix, 0)
10 print(“Sampling:”)
11 print(“list of sampled indices:\n”, indices)

in sample(parameters, char_to_ix, seed)
69 # Step 4: Overwrite the input x with one that corresponds to the sampled index idx.
70 # (see additional hints above)
—> 71 x = np.zeros(x)
72 x[idx] = ix_to_char[idx]
73

TypeError: only integer scalar arrays can be converted to a scalar index

Debugging trace:
a dims:(100, 1)
z dims:(27, 1)
y dims:(27, 1)

What is wrong? I don’t find it.

Your code for setting the x value is incorrect.
The size of x is the same as the vocab_size.
Once you set it to all-zeros, then you set just one element to the value 1.

1 Like

Yes, thank you. All done now.

Hello, I am having the same issue as gborden1 on May 13: " ‘a’ and ‘p’ must have same size"

I am using a = range(vocab_size), and p = y.ravel().
vocab_size =27, and y.ravel() is (27,), so it looks like they do have the same size. I’d appreciate any suggestions.

Rachel

The difference is the comma.
Try (vocab_size,1)

4 Likes

One issue was the difference between range() and np.arange(). Now my test shows the shapes of a and p are both (27,), but I’m still getting the error that “‘a’ and ‘p’ must have same size”.

I got it working! This thread was extremely helpful. Thanks!