# DLS 5, Week 1 assignment 2, Ex 2 choice parameters a and p are not the same size

**URL:** <https://community.deeplearning.ai/t/dls-5-week-1-assignment-2-ex-2-choice-parameters-a-and-p-are-not-the-same-size/72157>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [December 6, 2021, 3:06am UTC](https://community.deeplearning.ai/t/dls-5-week-1-assignment-2-ex-2-choice-parameters-a-and-p-are-not-the-same-size/72157 "2021-12-06T03:06:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GabrielBGutierrez](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@GabrielBGutierrez](https://community.deeplearning.ai/u/GabrielBGutierrez)\
**Post date:** [December 6, 2021, 3:06am UTC](https://community.deeplearning.ai/t/dls-5-week-1-assignment-2-ex-2-choice-parameters-a-and-p-are-not-the-same-size/72157/1 "2021-12-06T03:06:17Z")

</div>

hey I’m getting this error on the choice part of the code:

```auto
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-78-a13d660e654a> in <module>
     19 print("\033[92mAll tests passed!")
     20 
---> 21 sample_test(sample)

<ipython-input-78-a13d660e654a> 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-77-323a9e4e9818> in sample(parameters, char_to_ix, seed)
     58 # Step 3: Sample the index of a character within the vocabulary from the probability distribution y
     59 # (see additional hints above)
---> 60 idx = np.random.choice(list(range(0, vocab_size)), p = y.ravel())
     61 
     62 # Append the index to "indices"

mtrand.pyx in numpy.random.mtrand.RandomState.choice()

ValueError: 'a' and 'p' must have same size

```

y have a shape (27, 100)

is the problem in how I’m calling choice or the problem is in the y calculation?

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [December 6, 2021, 3:19am UTC](https://community.deeplearning.ai/t/dls-5-week-1-assignment-2-ex-2-choice-parameters-a-and-p-are-not-the-same-size/72157/2 "2021-12-06T03:19:19Z")

</div>

The shape of your y value is wrong. I added a bunch of print statements to my code to show the sizes of things. Here’s what I get:

```auto
vocab_size = 27
Wax (100, 27) x (27, 1) Waa (100, 100) a_prev (100, 1)
Wya (27, 100) x (100, 1) + by (27, 1)
y.shape (27, 1)
len(y) 27
len(y.ravel()) 27

```

Comparing the sizes you get should give you a pointer to where things go off the rails.

---

<div class="post-metadata">

**Author:** ![GabrielBGutierrez](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@GabrielBGutierrez](https://community.deeplearning.ai/u/GabrielBGutierrez)\
**Post date:** [December 6, 2021, 6:07am UTC](https://community.deeplearning.ai/t/dls-5-week-1-assignment-2-ex-2-choice-parameters-a-and-p-are-not-the-same-size/72157/3 "2021-12-06T06:07:28Z")

</div>

Thanks! That helped a lot!
