Unable to figure out why I get this error
(
import math
from public_tests import *
GRADED FUNCTION: basic_sigmoid
def basic_sigmoid(x):
“”"
Compute sigmoid of x.
Arguments:
x – A scalar
Return:
s – sigmoid(x)
“”"
# (≈ 1 line of code)
# s =
# YOUR CODE STARTS HERE
s = (1 / (1 + math.exp(-x)) )
# YOUR CODE ENDS HERE
return s
print("basic_sigmoid(1) = " + str(basic_sigmoid(1)))
basic_sigmoid_test(basic_sigmoid)
basic_sigmoid(1) = 0.7310585786300049
All tests passed.
Actually, we rarely use the “math” library in deep learning because the inputs of the functions are real numbers. In deep learning we mostly use matrices and vectors. This is why numpy is more useful.
One reason why we use “numpy” instead of “math” in Deep Learning
x = [1, 2, 3] # x becomes a python list object
basic_sigmoid(x) # you will see this give an error when you run it, because x is a vector.
TypeError Traceback (most recent call last)
in
2
3 x = [1, 2, 3] # x becomes a python list object
----> 4 basic_sigmoid(x) # you will see this give an error when you run it, because x is a vector.
in basic_sigmoid(x)
18 # YOUR CODE STARTS HERE
19
—> 20 s = (1 / (1 + math.exp(-x)) )
21
22 # YOUR CODE ENDS HERE
TypeError: bad operand type for unary -: ‘list’