Python ``TensorFlow math.sigmoid()`` 函数与可视化示例


发布日期 : 2019-05-07 13:47:40 UTC

访问量: 10 次浏览

Python – tensorflow.math.sigmoid()

TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

sigmoid()用于查找x的元素明智的 sigmoid

语法

tensorflow.math.sigmoid(x, name)

参数

  • x:它是一个张量。允许的 dtypes 是float16, float32, float64, complex64, 或 complex128。
  • name(可选):它定义了该操作的名称。

返回:它返回一个与x具有相同 dtype 的张量。

示例

示例 1:

# 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)

输出:

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:视觉化

# 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()

输出:

Python – tensorflow.math.sigmoid()")