Course 2 Week 2 Excercise 3

I am initializing velocity using the def initialize_velocity(parameters). My code is:
v[“dW” + str(l)] = np.zeros(parameters[“W” + str(l)].shape)
v[“db” + str(l)] = np.zeros(parameters[“b” + str(l)].shape)

However, there are errors occured as:
TypeError Traceback (most recent call last)
in
2
3 v = initialize_velocity(parameters)
----> 4 print(“v[“dW1”] =\n” + str(v[“dW1”]))
5 print(“v[“db1”] =\n” + str(v[“db1”]))
6 print(“v[“dW2”] =\n” + str(v[“dW2”]))

TypeError: ‘NoneType’ object is not subscriptable

I tried several times, but canno0t solve this problem. Can anyone help me ? Thanks!

Are you sure you did not change the indentation of the code in initialize_velocity? Indentation matters in python: for example, it determines whether a statement is part of a for loop or not.

yes, I am sure that I did not change the indentation. Could you offer me more suggestion? Thanks a lot

{moderator edit - solution code removed}

It looks like you modified the “return” statement to remove the variable that it is supposed to return. That was part of the given code. Here’s what it looks like in my notebook:

return v

The way you modified the code, it no longer returns a value, which is why you got that error message.