1
00:00:00,140 --> 00:00:06,980
A variable maintains shared persistent state manipulated by a program, so the variable constructor

2
00:00:06,980 --> 00:00:13,040
requires an initial value for the variable, which is in this case a tensor which can be a tensor of

3
00:00:13,040 --> 00:00:14,330
any type and shape.

4
00:00:14,330 --> 00:00:18,530
Then this initial value defines the type and shape of the variable.

5
00:00:18,530 --> 00:00:22,010
So after construction, the type and shape of the variable is fixed.

6
00:00:22,010 --> 00:00:26,330
The value can be changed using one of the assigned methods.

7
00:00:26,330 --> 00:00:35,000
Now that said, um, if we consider our model to be, let's say this block and we have some inputs,

8
00:00:35,000 --> 00:00:40,700
data and let's say input data and some output data.

9
00:00:41,370 --> 00:00:49,860
And then, um, in our model we update or we have our weights, we have our weights, which we want

10
00:00:49,860 --> 00:00:54,300
to update based on this inputs and this outputs.

11
00:00:54,300 --> 00:00:59,250
These weights can be represented as TensorFlow variables.

12
00:00:59,250 --> 00:01:05,340
Let's see how we could create one very easily and also how to update or modify its values.

13
00:01:05,340 --> 00:01:07,050
So here we have x.

14
00:01:07,230 --> 00:01:08,910
Um TensorFlow.

15
00:01:08,910 --> 00:01:10,200
That's a tensor.

16
00:01:10,320 --> 00:01:13,680
We have X12345.

17
00:01:13,830 --> 00:01:16,320
And then we create x var.

18
00:01:16,320 --> 00:01:18,030
So this is our TensorFlow variable.

19
00:01:18,030 --> 00:01:24,900
Now TensorFlow variable and initialized um or it's initialized with the value x.

20
00:01:24,900 --> 00:01:30,210
So we run that tool and then we have x var um assign.

21
00:01:30,210 --> 00:01:32,370
Or let's first of all print out x var.

22
00:01:32,370 --> 00:01:34,200
Let's print out x and then x var.

23
00:01:34,260 --> 00:01:36,930
You see how we have x which is our tensor.

24
00:01:36,930 --> 00:01:39,600
And then we have x var which is a variable.

25
00:01:39,600 --> 00:01:45,780
See uh notice how it takes the exact same shape of um the tensor which was used to initialize it.

26
00:01:46,290 --> 00:01:48,300
Um and also the values are the same.

27
00:01:48,300 --> 00:01:49,260
So that's it.

28
00:01:49,260 --> 00:01:52,680
Now let's do um x var x bar.

29
00:01:52,680 --> 00:01:53,640
Let's modify the value.

30
00:01:53,640 --> 00:01:56,250
So we have x var assign add.

31
00:01:56,250 --> 00:02:00,600
So also note that all these different methods like assign add assign sub.

32
00:02:00,630 --> 00:02:03,600
I found the documentation and feel free to check them out.

33
00:02:03,600 --> 00:02:07,170
So we have assigned add let's say assign add um five.

34
00:02:07,170 --> 00:02:11,550
Let's run that and we are given a variable with shape five.

35
00:02:11,550 --> 00:02:15,660
Using the tensor we shape uh with an empty shape was uh be equal.

36
00:02:15,660 --> 00:02:17,160
So let's get back.

37
00:02:17,760 --> 00:02:18,900
We have that.

38
00:02:18,900 --> 00:02:20,160
Let's add five.

39
00:02:21,180 --> 00:02:22,830
Still doesn't work.

40
00:02:22,830 --> 00:02:24,870
Um, using tensor with shape one.

41
00:02:24,870 --> 00:02:29,460
So this shows us that the it doesn't take into consideration broadcasting.

42
00:02:29,460 --> 00:02:34,980
So we'd have to manually write this out five um five and five.

43
00:02:34,980 --> 00:02:36,090
Run that again.

44
00:02:36,330 --> 00:02:42,900
And then you see we have this, our new variable where we have added up all the different values.

45
00:02:42,900 --> 00:02:46,470
You could change this to stop run that again.

46
00:02:47,070 --> 00:02:48,510
And there we go.

47
00:02:48,540 --> 00:02:50,970
Um, well we did sub of x var okay.

48
00:02:50,970 --> 00:02:53,190
Since we had x var already added.

49
00:02:53,190 --> 00:02:55,200
Now when you do sub it gets back to his original value.

50
00:02:55,200 --> 00:02:58,860
If we run this sub again you see we have now negative values.

51
00:02:59,220 --> 00:03:03,270
You could also just directly assign values using the assign method.

52
00:03:03,270 --> 00:03:07,980
So let's let's say we have x var x var assign.

53
00:03:07,980 --> 00:03:15,030
And then we do um let's say 5555.

54
00:03:15,030 --> 00:03:16,230
Run that again.

55
00:03:16,500 --> 00:03:19,440
And you see now that the values are directly assigned.

56
00:03:19,440 --> 00:03:23,550
So that's it for this section on tensors and variables.

57
00:03:23,550 --> 00:03:26,970
See you in the next section where we shall dive into linear regression.
