#deep-learning-specialization:dls-course-5 W1A2 exercise 2


Dear community,
I tried everything I could but it still not fixed. I’m not sure where the problems occurs. At first, I got problems with the dimension while initiating a_prev and after fixing them this happened.

Please read the step 3 instructions again, carefully. They also give you an example in the instructions. What is prob here? It’s not y. Also, you have to use ravel.

y = softmax(z).ravel()
I have already implemented this sir, and the problem kept going

Your range is also wrong.

could you please make it a little bit clearer sir?
I’ve tried this implementation idx = np.random.choice(range(len(y.ravel())), p = y.ravel()) and read the step 3 instructions very carefully, but the same problem occured :frowning:

From notebook:

np.random.seed(0)
probs = np.array([0.1, 0.0, 0.7, 0.2])
idx = np.random.choice(range(len(probs)), p = probs)

What is the first argument to random.choice? prob length in this example is 4 (or you can say it is the size), So, how to implement this in the below function?
Also, you have to use ravel in one place only. Check this point:

  • Note that the value that’s set to p should be set to a 1D vector.

actually the problem comes from step 4, I overwrite the input x with the wrong dimension. Thank you sir!