Week 3 Assignment problem What is this 2 steps

logprobs = np.multiply(np.log(A2),Y)
cost = - np.sum(logprobs)

What is this operation? If we do element wise and then sum it will not do the matrix multiplication.

These two steps are equivalent to using np.dot() in one step. The assignment notebook explained it effectively:

2 Likes

The other important thing to note is that the sample code shown there is not the complete implementation of the cost. It is just showing you one approach for doing the computation, as Saif has pointed out.

Sorry I did not ask the question correctly. What I mean to ask is np.multiply is elementwise multiplication and sum is lets say row wise sum, this is not same as matrix multiplication how is this same as np.dot() ??

If the two operands are vectors, it is the same as dot product: you compute the elementwise products and then sum the results.

1 Like

Perfect, Thankyou.

Both the operands are 1 x m vectors in this case, right?

1 Like

Yes Correct I get it now.