W1 Dinosaur Island 2.2 Sampling Key Error

My code seems to be appropriately implemented, but I cannot get the letter corresponding to the idx (the one hot vector).

It seems that I am trying to get index 23 from a dictionary where the dictionary is holding this as:
{…, ‘w’: 23, …}. I am having a hard time trying to access this letter, given the index. I tried get(), but it was returning a None. I would appreciate guidance.

Share the screenshot of the output you are getting, and the related issues posts are there in the community, did you try searching??

I tried searching, and could not find something helpful.

None
{'\n': 0, 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
None
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-118-5ed45dfbad4e> in <module>
     19     print("\033[92mAll tests passed!")
     20 
---> 21 sample_test(sample)

<ipython-input-118-5ed45dfbad4e> 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)

<ipython-input-117-193ccbd974ec> in sample(parameters, char_to_ix, seed)
     69         x = char_to_ix.get(idx)
     70         print(x)
---> 71         x[idx] = x
     72 
     73         # Update "a_prev" to be "a"

TypeError: 'NoneType' object does not support item assignment

which weeks’ assignment is this?

x[idx] should be set to 1

It is week 1. That did not seem to fix the issue. I initialized x as zeros before the for loop, with the number of rows being the number of characters with one column. I should be setting x to a vector, but I have to bring the computed value in somewhere per the directions “Overwrite the input x with one that corresponds to the sampled index idx.”

So I need to produce a new x vector, but it is unclear how I pull in the values calculated before this point.

Can you please share your notebook in the personal DM. Click my name and then message. Do not post code on public post threads.

Regards
DP

Sent, thanks

I just figured it out. You have to re-initialize a vector of zeros for x in that first line, per the additional hints.

Good job, finding a solution yourself shows your sincere effort towards learning even after you are looking for help, you still working on your issue is smart person’s choice.

Happy Learning!!!
Regards
DP