`nan` cost when normalizing image with standard deviation instead of division by 255

As suggested on the end of week2 assignment I tried to standardize the images dividing every pixel value by the images standard deviation. That resulted on a 100% accuracy on the training set and 72% on the test set (an improvement of 2%), but all my cost values was reported as nan. I used (-1/m)*(np.sum((np.dot(Y,np.log(A).T)+np.dot(1-Y,np.log(1-A).T))) for the cost function and I figure that the problem was on the np.dot(1-Y,np.log(1-A).T) part, but I don’t know why. 1-Y and np.log(1-A).T are working fine, but the dot product generate nan results. I am guessing there are some really small numbers for np.log(1-A).T and this results in overflow, but I am not a CS guy to be sure about that. Any ideas on how to fix that? Also, I don’t understand how the model still works on that scenario. tks

Hi @jalvespinto,

Can you share your lab ID with me ? In the assignment, when you click the top right “Help” button, a panel will open and your lab ID will be shown at the bottom.

I shall take a look.

When you reply back, kindly tag me in the post so that I’m notified.