Also, I am not crazy about it but the way Prof. Ng has us doing this is calculating ‘cost’ in two steps (thus logprobs). Really it can be done all on one line.

In the first snippet, the computation only considers the case where the true label is 1, neglecting the case where it’s 0. Additionally, the logarithms of predicted probabilities are not properly negated.

In the second snippet, the dot product between the true labels and the transposed logarithms of predicted probabilities is incorrect for this context. To fix these issues, ensure both cases (true label being 1 and 0) are accounted for in the computation, and properly negate the logarithms of predicted probabilities.

Please check the formula again and reconsider the way you are trying to implement this function!