# Programming Assignment: Logistic Regression with a Neural week1

## (2, 1) (2, 3) (2, 1) (2, 3) (2, 2) (2, 3)

ValueError Traceback (most recent call last)
in
----> 1 params, grads, costs = optimize(w, b, X, Y, num_iterations=100, learning_rate=0.009, print_cost=False)
2
3 print ("w = " + str(params[“w”]))
4 print ("b = " + str(params[“b”]))
5 print ("dw = " + str(grads[“dw”]))

in optimize(w, b, X, Y, num_iterations, learning_rate, print_cost)
41 print(X.shape)
42 # w=w.reshape(X[0].shape,1)
—> 43 grads, cost = propagate(w, b, X, Y)
44
45

in propagate(w, b, X, Y)
36 # assert w.shape == (X.shape[0], 1)
37 # w = w.reshape(X.shape[0], 1)
—> 38 A=sigmoid(np.dot(w.T,X)+b)
39 cost=-1/mnp.sum(Ynp.log(A)+(1-Y)*np.log(1-A))
40 ‘’'Here’s why we need to use element-wise multiplication instead of dot product in the cost calculation:

ValueError: operands could not be broadcast together with shapes (2,3) (2,2) .
I am getting this error while running the optimize function.
im printing the size of w then X.
so in the first two iterations the size of w is 2,1 its fine ,but in the third iteration its becoming 2,2.
i even tried resizing it to 2,1 (now commented part) but it says cannot resize an array of size 4.
im not understanding the root cause for this and am rly stuck, any feedback will be greatly appreciated.

You’re encountering a dimension mismatch error. Try checking the shapes of the arrays involved and verify the dimensions of the transpose operation. Also, make sure you don’t unintentionally reshape arrays.

If your problem persists, feel free to send your code in a private message, and we will work it out together!

1 Like

This is the test case for the optimize function it looks like. The operation that involves “broadcasting” there is adding the b value to the results of the dot product w^T \cdot X. So how did b end up being a 2 x 2 array? It should be a scalar value, right?

Also note that 2 x 3 is not the correct shape for w^T \cdot X. The dimensions on that dot product should be 1 x n_x dot n_x x m. So the results should be 1 x m, which would be 1 x 3 with the test case here.

My guess is that it is a problem in how your “update parameters” logic works. Maybe you are not adding the correct gradient values. Please compare that code that updates w and b carefully to the math formulas shown in the instructions.

1 Like

Thank You for the suggestions .It was a minor formula error in update parameters .On rectifying that the whole model worked well.

1 Like

Nice work! Thanks for confirming that it is all good now.