A variable maintains shared persistent state manipulated by a program, so the variable constructor
requires an initial value for the variable, which is in this case a tensor which can be a tensor of
any type and shape.
Then this initial value defines the type and shape of the variable.
So after construction, the type and shape of the variable is fixed.
The value can be changed using one of the assigned methods.
Now that said, um, if we consider our model to be, let's say this block and we have some inputs,
data and let's say input data and some output data.
And then, um, in our model we update or we have our weights, we have our weights, which we want
to update based on this inputs and this outputs.
These weights can be represented as TensorFlow variables.
Let's see how we could create one very easily and also how to update or modify its values.
So here we have x.
Um TensorFlow.
That's a tensor.
We have X12345.
And then we create x var.
So this is our TensorFlow variable.
Now TensorFlow variable and initialized um or it's initialized with the value x.
So we run that tool and then we have x var um assign.
Or let's first of all print out x var.
Let's print out x and then x var.
You see how we have x which is our tensor.
And then we have x var which is a variable.
See uh notice how it takes the exact same shape of um the tensor which was used to initialize it.
Um and also the values are the same.
So that's it.
Now let's do um x var x bar.
Let's modify the value.
So we have x var assign add.
So also note that all these different methods like assign add assign sub.
I found the documentation and feel free to check them out.
So we have assigned add let's say assign add um five.
Let's run that and we are given a variable with shape five.
Using the tensor we shape uh with an empty shape was uh be equal.
So let's get back.
We have that.
Let's add five.
Still doesn't work.
Um, using tensor with shape one.
So this shows us that the it doesn't take into consideration broadcasting.
So we'd have to manually write this out five um five and five.
Run that again.
And then you see we have this, our new variable where we have added up all the different values.
You could change this to stop run that again.
And there we go.
Um, well we did sub of x var okay.
Since we had x var already added.
Now when you do sub it gets back to his original value.
If we run this sub again you see we have now negative values.
You could also just directly assign values using the assign method.
So let's let's say we have x var x var assign.
And then we do um let's say 5555.
Run that again.
And you see now that the values are directly assigned.
So that's it for this section on tensors and variables.
See you in the next section where we shall dive into linear regression.