Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i solve this sigmoid function in coursera?

Tags:

python

how can i solve this?

2.2 - Computing the Sigmoid Amazing! You just implemented a linear function. TensorFlow offers a variety of commonly used neural network functions like tf.sigmoid and tf.softmax. For this exercise, compute the sigmoid of z.

In this exercise, you will: Cast your tensor to type float32 using tf.cast, then compute the sigmoid using tf.keras.activations.sigmoid.

Exercise 2 - sigmoid Implement the sigmoid function below. You should use the following:

tf.cast("...", tf.float32)
tf.keras.activations.sigmoid("...")
# GRADED FUNCTION: sigmoid
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 = ...
    # a = ...
    # YOUR CODE STARTS HERE
    
    
    # YOUR CODE ENDS HERE
    return a
like image 604
Amir Kamran Pezeshkmehr Avatar asked Nov 01 '25 07:11

Amir Kamran Pezeshkmehr


1 Answers

Well, you should figure out your assignment by yourself.. But it is written in the task:

tf.cast("...", tf.float32) tf.keras.activations.sigmoid("...")

They tell you everything by this line. So the solution looks almost like this:

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 = ...
    # a = ...
    # YOUR CODE STARTS HERE
    z = tf.cast(z, tf.float32)
    a = tf.keras.activations.sigmoid(INSERT Z VARIABLE HERE)

    # YOUR CODE ENDS HERE
    return a

You need to make small adjustment to the code, hope you will find it.

like image 182
Minarth Avatar answered Nov 02 '25 22:11

Minarth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!