how can i solve this sigmoid function in coursera?

Viewed 1352

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
2 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.

This very easy Just google it otherwise See this below code it might help in your problem.

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import math
def sigmoid(z):
    return 1 / (1 + math.exp(-z))
print(sigmoid(0.5))
Related