Code Explanation:
1. Importing TensorFlow
import tensorflow as tf
This line imports the TensorFlow library, a popular framework for machine learning and deep learning tasks.
tf is the alias used to refer to TensorFlow functions and modules.
2. Creating a Tensor
x = tf.constant([-1.0, 0.0, 1.0])
tf.constant() creates an immutable tensor (a multi-dimensional array) with the values [-1.0, 0.0, 1.0].
Tensors are similar to NumPy arrays and are the core data structure in TensorFlow.
3. Applying the Sigmoid Function
sigmoid = tf.nn.sigmoid(x)
tf.nn.sigmoid() applies the sigmoid activation function element-wise to the input tensor.
It squashes the input values to a range between 0 and 1, making it useful for binary classification tasks.
Applying to each input value:
4. Printing the Result
print(sigmoid)
This prints the output tensor containing the sigmoid values for each input.
The expected output will be:
[0.26894143 0.5 0.7310586]
TensorFlow may display it with additional information like data type (dtype) depending on the environment.
0 Comments:
Post a Comment