Python – tensorflow.math.sigmoid()
TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
sigmoid()用于查找 x 的元素 sigmoid。
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.
示例 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)
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()
输出:
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)
示例 2:可视化
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()
输出: