Course 2 Week 1 Assignment 2: Cant Broadcast together, wrong shape, weird shape at the end

Hello together,

i normally program with tensorflow(keras) and i just did this course to get into deep learning, cause we dont have anything about ai currently at my academy (germany), so i learned all by myself and internet.
Now i encountered following problem at the second assignment:

ValueError Traceback (most recent call last)
----> 1 parameters = model(train_X, train_Y, keep_prob = 0.86, learning_rate = 0.3)
3 print (β€œOn the train set:”)
4 predictions_train = predict(train_X, train_Y, parameters)
5 print (β€œOn the test set:”)

in model(X, Y, learning_rate, num_iterations, print_cost, lambd, keep_prob)
32 a3, cache = forward_propagation(X, parameters)
33 elif keep_prob < 1:
β€”> 34 a3, cache = forward_propagation_with_dropout(X, parameters, keep_prob)
36 # Cost function

in forward_propagation_with_dropout(X, parameters, keep_prob)
42 D1 = np.random.rand(2,5)
43 D1 = (D1 < keep_prob).astype(int)
β€”> 44 A1 = A1*D1
45 A1 = A1/keep_prob

ValueError: operands could not be broadcast together with shapes (20,211) (2,5)

( All tests before passed, just want to clarify that the code is really working )
The Error occurs at the codeblock where you change the keep_prob from 0.8 to 0.86.
I do understand that numpy cant broadcast a (20,211) shape with a (2,5).
But why does this even occur?
Sure when i change the keep_prob the the overall weights and shapes do change not the exact same as with 0.8, cause i drop less. ( If i understood it correctly, the 211 is the problem here )
But what do I have to do, to get this working ?
( I just skipped Course 1, cause i got one free course about the coursera students program and i thought i owned already over the internet the knowledge from course 1. Maybe i missed something there, which leads to this problem )

Would be happy if someone can help me with this problem.

Nevermind found the issue by overthinking it again.
The mask have to rescale with the iteration, as so on i have to use the shape function.

1 Like