Skip to content
Related Articles

Related Articles

Python – tensorflow.math.sigmoid()

Improve Article
Save Article
  • Last Updated : 05 Nov, 2021
Improve Article
Save Article

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks.

sigmoid() is used to find element wise sigmoid of x.

Syntax: tensorflow.math.sigmoid(x, name)

Parameters:

  • x: It’s a tensor. Allowed dtypes are float16, float32, float64, complex64, or complex128.
  • name(optional): It defines the name for the operation.

Return: It return a tensor of same dtype as x.

Example 1:

Python3




# importing the library
import tensorflow as tf
 
# Initializing the input tensor
a = tf.constant([.2, .5, .7, 1, 2, 5, 10], dtype = tf.float64)
 
# Printing the input tensor
print('a: ', a)
 
# Calculating result
res = tf.math.sigmoid(x = a)
 
# Printing the result
print('Result: ', res)


Output:

a:  tf.Tensor([ 0.2  0.5  0.7  1.   2.   5.  10. ], shape=(7, ), dtype=float64)
Result:  tf.Tensor(
[0.549834   0.62245933 0.66818777 0.73105858 0.88079708 0.99330715
 0.9999546 ], shape=(7, ), dtype=float64)
 
 
 
 

Example 2: Visualization

Python3




# importing the library
import tensorflow as tf
import matplotlib.pyplot as plt
 
# Initializing the input tensor
a = tf.constant([.2, .5, .7, 1, 2, 5, 10], dtype = tf.float64)
 
# Calculating result
res = tf.math.sigmoid(x = a)
 
# Plotting the graph
plt.plot(a, res, color = 'green')
plt.title('tensorflow.math.sigmiod')
plt.xlabel('Input')
plt.ylabel('Result')
plt.show()


Output:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!