Hello I am getting error in this exercise.

Perhaps my code is wrong or I implemented it wrong.

Kinldy help.

Hi @sousinha. The traceback indicates that you are not applying the rules of matrix algebra properly. Note that you are using the element-by-element multiplication operator (*), leading to the error. Only matrices/vectors of the same size will conform to that operation. In the â€śTipsâ€ť section of the docstring (the information between triple quotes at the top of the function), you will find the function for the matrix operation that you need to apply.

Also note that once you fix the error that @kenb has pointed out, there are several more errors in the code as currently shown. The cost line will throw an error because *np.loga* is not the name of a numpy function and *log* is also not a numpy function. Youâ€™ll also get an error thrown by the line that computes dw. It will be something along the lines of â€śUnable to invoke non-function objectâ€ť. What is the operation that you want to invoke between X and (A - Y)^T?

Hello paulinpaloato,

I want to implement the cost function, I am getting an error here, I beileive the correct expression will be np.log(a) for numpy function.

for dw I am multiplying by * operator between X and (A-Y).T

Yes, *np.log(a)* is correct for that term.

For the dw calculation, that operation is a dot product style matrix multiply, not elementwise (*). You have to understand Prof Ngâ€™s notational conventions when he is writing math formulas: when he means elementwise multiply, he will always use *. When he writes the operands adjacent with no operators, then he means â€śrealâ€ť dot product style matrix multiply. It would be better if he used a more explicit notation as in:

dw = \displaystyle \frac {1}{m} X \cdot (A - Y)^T

But he didnâ€™t ask my opinion, so we just have to understand his notation.

The other important point is that python is not the same as math. If you write this:

foo = X(A-Y).T

in python, that means that X is a function and you are invoking it with the argument (A - Y) and then taking the transpose. That will not work out well in the example at hand.