import tensorflow as tf
# Variables are manipulated via the tf.Variable class.
# A tf.Variable represents a tensor whose value can be changed by running ops on it.
# Specific ops allow you to read and modify the values of this tensor.
## Creaging a Variable
with tf.name_scope("my"):
variable = tf.Variable(1)
print("tensor:", variable)
print("value:", variable.numpy())
tensor: <tf.Variable 'my/Variable:0' shape=() dtype=int32, numpy=1> value: 1
## Using Variables
# To use the value of a tf.Variable in a TensorFlow graph, simply treat it like a normal tf.Tensor
variable = variable + 1
print("value:", variable.numpy())
value: 2
## Using Variables
# To use the value of a tf.Variable in a TensorFlow graph, simply treat it like a normal tf.Tensor
variable = tf.Variable(2)
variable.assign_add(1)
print("value:", variable.numpy())
value: 3