Compute sigmoid value of a Tensor with tf.sigmoid – TensorFlow Math Function

By | April 18, 2019

tf.sigmoid can compute sigmoid value of a tensor and return value in (0,1), in this tutorial, you can use it easily by following our steps.

How to use tf.sigmoid function?

Step 1. Define a tensor

import tensorflow as tf
import numpy as np
t=np.array([[1,0,0,0,0],[0,1,0,0,0],[3,0,1,0,0],[0,1,0,0,0],[0,0,0,0,1],[0,0,1,0,0],[0,1,0,0,0],[0,1,0,0,1]]) #convert a numpy to a tensor
tt=tf.convert_to_tensor(t, tf.float32)

Step 2. Use tf.sigmoid to compute

so = tf.sigmoid(tt)

Step 3. Print the result

init = tf.global_variables_initializer() 
init_local = tf.local_variables_initializer()
with tf.Session() as sess:[init, init_local])
    np.set_printoptions(precision=4, suppress=True)
    max_index= ([so]))
    print max_index

the result is:

tf.sigmoid result

Notice: tf.sigmoid only compute each element, no axis selection.

Leave a Reply

Your email address will not be published. Required fields are marked *