Course 1, Week 4, Assignment 2, Exercise 1

Hi all,

I’m having an issue with the first exercise–seems like a pretty simple issue but I can’t quite spot what I need to change:

in two_layer_model(X, Y, layers_dims, learning_rate, num_iterations, print_cost)
—> 90 parameters = update_parameters(parameters, grads, learning_rate)

~/work/release/W4A2/ in update_parameters(parameters, grads, learning_rate)
378 # Update rule for each parameter. Use a for loop.
379 for l in range(L):
→ 380 parameters[“W” + str(l+1)] = parameters[“W” + str(l+1)] - learning_rate * grads[“dW” + str(l+1)]
381 parameters[“b” + str(l+1)] = parameters[“b” + str(l+1)] - learning_rate * grads[“db” + str(l+1)]

TypeError: can’t multiply sequence by non-int of type ‘float’

Values for dW1 (as an example) are currently being stored as a tuple of arrays, which seems like it could be the issue (attempting to multiply the learning_rate, a float, by a tuple, dW1).

Any ideas?

My guess is that you are misinterpreting the symptoms here. It is not a problem to multiply a float times a numpy array. The next step to debugging this would be to print the types and shapes of the various grads values. My guess is you will find one of them is not what was intended.

Or if you are saying that you’ve done that and already know that dW1 is a tuple, than that is the problem. It should be a numpy array of the same shape as W1. So how did that happen?

One other question: I hope you did not “hand import” any of your routines from the “Step by Step” assignment here. If so, that is a mistake. They provide their own known correct implementations.

Thank you Paul (I live about 20 mins away from you by the way!)

Turns out I forgot to name the function I wanted to call, and just listed the inputs

(i.e. I wrote a, b, c = (d, e, f) instead of a, b, c = return_abc(d, e, f).


Hi, David.

That’s great to hear that you found the solution. Onward! :nerd_face: