# Week 2 Exercise 5 - propogate function log returns NAN and dimension mismatch

When trying to calculate the cost function
I’m using the resulting A values and taking the log of them, but I’m getting a nan
Why am I getting a nan? do we need to normalize these numbers?

A = [ 8.5 0.5 -5.9]
log(A) = [ 2.14006616 -0.69314718 nan]

also, I get a ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0)
in the cost function. I’m not sure I understand the 3 (dim 1) != (dim 0)

Thanks

It looks like your sigmoid function is incorrect or you’re not applying it. The A values are the output of sigmoid, so that means they should be between 0 and 1, right? If you take the log of a negative number like -5.9, that will not end well.

I’m guessing the dimension mismatch is on the cost calculation. It’s fine to use the dot product for that, but you need to transpose one of the operands or it doesn’t work. If A and Y are both 1 x 3, then just dotting them as is doesn’t work. The alternative is just to use elementwise multiply (“*”) followed by `np.sum`. Here’s a thread which discusses this in more detail.

1 Like

Thank you Paul!