Error in 'Computing the cost' from Tensorflow Tutorial

Hello everybody
Does somebody get a different result when compute the cost function using numpy?


Since logits = y_hat and y = np.array([0.0, 0.0, 1.0, 1.0]) if i compute the cost function using numpy i will get:

I will appreciate your support

Are you working on the C2 W3 “Tensorflow_introduction” notebook?

If so, you’re expected to use tensorflow functions here, not numpy.

Your line “cost = cost(…)” seems problematic, since you’re using the same name for both a function and its return value.

Note also that “cost” should not be an array. It’s a scalar value.

In addition to Tom’s point, note that there is no function called “cost()” in that notebook. So did you write the function that you called in your first example that gave values > 1? There must be some problem with that code.

Also note that in python, you have to be a bit careful about using the same variable name for two different purposes (to name a function and to name its return value). That will not end well if you later need to call that same function again.

Also note that the argument you pass to your cost() function that you call logits is not what Prof Ng or TF mean by “logits”. The standard definition of logits is the output of the linear function at the output layer before you have applied the non-linear activation (sigmoid in this case).

but tf.nn.sigmoid_cross_entropy_with_logits doesn’ return a scalar


in order to get the expected value is necessary to do it. so there is something wrong and this is my doubt

Please verify what notebook you re working on.

Also, do not add any cells to any course notebook. That will very likely make your code break the grader when you try to submit it.

Sorry, but I have the same question that Tom asked: I don’t see those expected values anywhere in the TensorFlow Introduction assignment (DLS C2 W3 A1).

So you must be working on some other exercise. In order to help, we need to make sure we are talking about the same thing.