Week 2 Exercise 3 - initialize_velocity

may i ask why i use this to set to 0 is not correct?
v[“dW” + str(l)] = np.zeros(np.shape(parameters[“W” + str(L)]))

1 Like

Assuming that you use right quotations, there is a capital “L” instead of “l”.

1 Like

Why do you do that? The for loop runs to the correct range.

Here’s the assignment code as in the notebook:

``````# GRADED FUNCTION: initialize_velocity

def initialize_velocity(parameters):
"""
Initializes the velocity as a python dictionary with:
- keys: "dW1", "db1", ..., "dWL", "dbL"
- values: numpy arrays of zeros of the same shape as the corresponding gradients/parameters.
Arguments:
parameters -- python dictionary containing your parameters.
parameters['W' + str(l)] = Wl
parameters['b' + str(l)] = bl

Returns:
v -- python dictionary containing the current velocity.
v['dW' + str(l)] = velocity of dWl
v['db' + str(l)] = velocity of dbl
"""

L = len(parameters) // 2 # number of layers in the neural networks
v = {}

# Initialize velocity
for l in range(1, L + 1):
# (approx. 2 lines)
# v["dW" + str(l)] =
# v["db" + str(l)] =
# YOUR CODE STARTS HERE

# YOUR CODE ENDS HERE

return v
``````