Sigmoid function, Week 3, Improving DNN

#######################CODE ##################################

def sigmoid(z):

"""
Computes the sigmoid of z

Arguments:
z -- input value, scalar or vector

Returns: 
a -- (tf.float32) the sigmoid of z
"""
# tf.keras.activations.sigmoid requires float16, float32, float64, complex64, or complex128.

# (approx. 2 lines)
# z = ...
# result = ...
# YOUR CODE STARTS HERE


# YOUR CODE ENDS HERE
return a

result = sigmoid(-1)
print ("type: " + str(type(result)))
print ("dtype: " + str(result.dtype))
print ("sigmoid(-1) = " + str(result))
print ("sigmoid(0) = " + str(sigmoid(0.0)))
print ("sigmoid(12) = " + str(sigmoid(12)))

def sigmoid_test(target):
result = target(0)
assert(type(result) == EagerTensor)
assert (result.dtype == tf.float32)
assert sigmoid(0) == 0.5, ā€œErrorā€
assert sigmoid(-1) == 0.26894143, ā€œErrorā€
assert sigmoid(12) == 0.9999939, ā€œErrorā€

print("\033[92mAll test passed")

sigmoid_test(sigmoid)

################## OUTPUT #################################
type: <class ā€˜tensorflow.python.framework.ops.EagerTensor’>
dtype: <dtype: ā€˜float32’>
sigmoid(-1) = tf.Tensor(
[[0.10371852]
[0.9506831 ]
[0.25175616]
[0.30040282]], shape=(4, 1), dtype=float32)
sigmoid(0) = tf.Tensor(
[[0.10371852]
[0.9506831 ]
[0.25175616]
[0.30040282]], shape=(4, 1), dtype=float32)
sigmoid(12) = tf.Tensor(
[[0.10371852]
[0.9506831 ]
[0.25175616]
[0.30040282]], shape=(4, 1), dtype=float32)

ValueError Traceback (most recent call last)
in
16 print(ā€œ\033[92mAll test passedā€)
17
—> 18 sigmoid_test(sigmoid)

in sigmoid_test(target)
10 assert(type(result) == EagerTensor)
11 assert (result.dtype == tf.float32)
—> 12 assert sigmoid(0) == 0.5, ā€œErrorā€
13 assert sigmoid(-1) == 0.26894143, ā€œErrorā€
14 assert sigmoid(12) == 0.9999939, ā€œErrorā€

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in bool(self)
982
983 def bool(self):
→ 984 return bool(self._numpy())
985
986 nonzero = bool

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

################################################################

Looks like you are redefining z variable instead of using the argument received by the sigmoid function.

Please edit your post so that the solution code is not explicitly displayed.

I hope that gives you a hint to solve the exercise, if not and you want to share your code with me you can do it by direct message.

Sir,

Thank you for the prompt response to my query.
Understood, sir.
I’ve made the changes and passed all tests.
Thank you.

I have also made the edit in the question. My apologies.