Dinosaurus exercise 2 generates name of length 18 when 22 is expected

Hello,

I’m working on exercise 2 of “dinosaurus”: Coursera | Online Courses & Credentials From Top Educators. Join for Free | Coursera

Somehow my sample function produces a list of 18 indices, but it looks like a length of 22 is expected. Can anyone help debug or provide a hint?

Here’s the error when running the sample_test:


/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py in within_tol(x, y, atol, rtol)
   2244     def within_tol(x, y, atol, rtol):
   2245         with errstate(invalid='ignore'):
-> 2246             return less_equal(abs(x-y), atol + rtol * abs(y))
   2247 
   2248     x = asanyarray(a)

ValueError: operands could not be broadcast together with shapes (18,) (22,)

I have a hunch step 3 is relevant, and here’s what I have:


        # Step 3: Sample the index of a character within the vocabulary from the probability distribution y
        # (see additional hints above)
        idx = np.random.choice(range(len(y[:,counter])), p=y[:,counter])

This is not right! You need to use range and ravel as per the instructions, also becareful how you use the counter here!