1
00:00:00,000 --> 00:00:05,486
In this second tutorial video on Octave,
I'd like to start to tell you how to move

2
00:00:05,486 --> 00:00:10,771
data around in Octave. So, if you have
data from a sheet learning problem, how do

3
00:00:10,771 --> 00:00:15,588
you load that data in Octave? How do you
put it into a matrix? How do you

4
00:00:15,588 --> 00:00:21,075
manipulate these matrices? How do you save
the results? How do you move data around

5
00:00:21,075 --> 00:00:27,684
and operate the data? Here's my active
window as before. Picking up from where we

6
00:00:27,684 --> 00:00:33,171
left off in the last video. If I type A,
that's the matrix that we generated,

7
00:00:33,171 --> 00:00:39,038
right? [inaudible] just command=1, two,
three, four, five, six. And, this is a

8
00:00:39,038 --> 00:00:45,979
three by two matrix. The size command in
[inaudible] let's you, Tells you what is

9
00:00:45,979 --> 00:00:52,124
the size of the matrix so size A returns
D2 it turns out that the size command

10
00:00:52,124 --> 00:00:58,501
itself is actually returning a 1x2 matrix
so you can actually set as Z = size of A

11
00:00:58,501 --> 00:01:04,568
and as Z is now a 1x2 matrix where the
first element of this is three and the

12
00:01:04,568 --> 00:01:11,023
second element of this is two. So you can
type size of as Z as Z is a 1x2 matrix

13
00:01:11,023 --> 00:01:17,790
who's two elements contain the dimensions
of the matrix A you can also type size A1.

14
00:01:17,790 --> 00:01:23,722
To give you back the first dimension of A
the size of the first dimension of A so

15
00:01:23,722 --> 00:01:29,934
that's the number of rows a size of two to
give you back a two which is the number of

16
00:01:29,934 --> 00:01:35,876
columns in the matrix A. If you have a
better V. So let's say V=1, two, three,

17
00:01:35,876 --> 00:01:42,455
four. And you type length V, what this
does is it gives you the size of the

18
00:01:42,455 --> 00:01:49,433
longest dimenstion. So, you can also type
length. A and because A is a three by two

19
00:01:49,433 --> 00:01:55,095
matrix the longer dimension is a size
three so this should entail three. But

20
00:01:55,095 --> 00:02:00,832
usually we apply we apply length only to a
vector. So, you know, length one, two,

21
00:02:00,832 --> 00:02:06,792
three, four, five rather than apply link
to matrixes because that's a, that's a

22
00:02:06,792 --> 00:02:12,893
little more confusing. Now. Lets look at
how to load data and find data on a file

23
00:02:12,893 --> 00:02:18,664
system. When we start on Octave we're
usually, we're often in a path that is you

24
00:02:18,664 --> 00:02:24,361
know the location of where the octave
program is so the PWD command shows the

25
00:02:24,361 --> 00:02:30,424
current directory or the current path that
Octave is in so right now we're in this

26
00:02:30,424 --> 00:02:36,559
somewhat maybe obscure directory the CD
command that stands for change directory

27
00:02:36,559 --> 00:02:42,736
so I can go to C color / user / ANG /
desktop. And, now I'm in your, my desktop.

28
00:02:42,736 --> 00:02:49,445
And if I type LS. Ls, is, sort of comes
from a Unix or Linux command. But LS will

29
00:02:49,445 --> 00:02:56,320
list the directories on my desktop and so,
you know, these are the files that are on

30
00:02:56,320 --> 00:03:18,060
my desktop right now. [sound], [sound] In
fact on my desktop are two files features

31
00:03:18,060 --> 00:03:24,685
X and price Y that maybe come from a
machine learning problem I want to solve

32
00:03:24,685 --> 00:03:31,246
so here's my desktop, here's features X.
And features x is this window, excuse me,

33
00:03:31,246 --> 00:03:37,342
is this file, with two columns of data.
This is actually my housing prices data.

34
00:03:37,342 --> 00:03:43,986
So I think, I think I have 47 rows in this
data set, and so, the first house at size

35
00:03:43,986 --> 00:03:50,160
204 square feet has three bedrooms, second
house has 1600 square feet, has three

36
00:03:50,160 --> 00:03:57,066
bedrooms, and so on. And price y is this
file. That, has the prices of the data in

37
00:03:57,066 --> 00:04:04,456
my training set. So, [inaudible] why I
just text files with my data. [inaudible]

38
00:04:04,456 --> 00:04:11,062
load this data into [inaudible] load
features X.dat. And if I do that, I load

39
00:04:11,062 --> 00:04:16,444
the features X, we can load price Y. Got
that. And by the way, there are multiple

40
00:04:16,444 --> 00:04:22,309
ways to do this. This command, if you put
features X dot dat in strings and load it

41
00:04:22,309 --> 00:04:29,720
like so, this is oops typo there this is
equivalent commands so you can but this

42
00:04:29,720 --> 00:04:36,623
way I'm just putting the file name with
the string and the file name in the string

43
00:04:36,623 --> 00:04:42,643
and with octave use single quotes to
represent strings like so, so that's a

44
00:04:42,643 --> 00:04:48,652
string and we can load. The file who's
name is given by that string. Now the who

45
00:04:48,652 --> 00:04:54,821
command now shows me what variables I have
in my active work space. So who shows me

46
00:04:54,821 --> 00:05:00,990
whether the variables the octave has in
memory currently features x and price y

47
00:05:00,990 --> 00:05:06,862
are among them as well as the variables
that we created in this session. So you

48
00:05:06,862 --> 00:05:14,872
can take features. X to display features X
and there's my data and I can type size

49
00:05:14,872 --> 00:05:23,039
features X and that's my 47x2 matrix and
sum of the size times Y that gives me my

50
00:05:23,039 --> 00:05:31,404
47x1 vector for this is a 47 dimensional
vector this tall column vector that has

51
00:05:31,404 --> 00:05:38,637
all the prices Y in my training set. Now
the who function. Show's you one of the

52
00:05:38,637 --> 00:05:43,832
variables that in the current workspace
there's also the who S variable that gives

53
00:05:43,832 --> 00:05:48,778
you the detail view and so this also with
an SIDN this also lists my variables

54
00:05:48,778 --> 00:05:54,161
except that it now listed sizes as well so
A is a 3x2 matrix and features X is a 47x2

55
00:05:54,161 --> 00:05:59,294
matrix by price Y is a 47x1 matrix meaning
this is just a vector and it shows you

56
00:05:59,294 --> 00:06:04,427
know how many bytes of memory it's taking
up as well as what type of data this is

57
00:06:04,427 --> 00:06:09,415
double means double position floating
points so that just means these are. Are

58
00:06:09,415 --> 00:06:15,615
a, a real value so floating-point numbers.
Now if you want to get rid of, of the

59
00:06:15,615 --> 00:06:21,694
variable, you can use the clear command.
So clear features X. And type who's again

60
00:06:21,694 --> 00:06:28,542
you notice that the features X variable
has now disappeared, and how do you see

61
00:06:28,542 --> 00:06:35,640
data let's see let's take a variable V and
set it to price Y one colon ten this sets

62
00:06:35,640 --> 00:06:42,662
V to be the first ten elements of, of the
vector Y so let's type who. Or whose,

63
00:06:42,662 --> 00:06:49,123
whereas Y was a 47 by one vector. V is now
ten by one, because V=price Y, one:10,

64
00:06:49,123 --> 00:06:56,615
this sets into the, just the first ten
elements of Y. Let's say I wanna save this

65
00:06:56,615 --> 00:07:02,982
to date, to just [inaudible] save,
hello.net and D. This will save the

66
00:07:02,982 --> 00:07:11,093
variable V into a file called hello.net.
So let's do that. And now. A file has

67
00:07:11,093 --> 00:07:16,042
appeared on my desktop called hello.net. I
happen to have had installed in this

68
00:07:16,042 --> 00:07:20,930
windows which is why you know this, this
icon looks like this because windows has

69
00:07:20,930 --> 00:07:25,878
recognized this as a.net file but don't
worry about it if this file looks like it

70
00:07:25,878 --> 00:07:31,007
has a different icon on your machine and
let's say I clear all my variables, so if

71
00:07:31,007 --> 00:07:36,137
I if you type clear without anything then
this actually deletes all the variables in

72
00:07:36,137 --> 00:07:40,964
your workspace, so type who's there's now
nothing left in the workspace and if I

73
00:07:40,964 --> 00:07:48,150
load hello.net. I can now load that, my
variable V which is my, That the data that

74
00:07:48,150 --> 00:07:53,809
previously saved into the hello.net file.
So hello.net what we did just now the save

75
00:07:53,809 --> 00:07:59,199
hello.net to [inaudible] this saved the
data in a binary format a somewhat more

76
00:07:59,199 --> 00:08:04,521
compressed binary format so that the V is
a wall of data this you know will be

77
00:08:04,521 --> 00:08:10,180
somewhat more compressed and take up less
the space if you want to save the data in

78
00:08:10,180 --> 00:08:15,435
a human readable format you type save
hello.text the variable V and then dash

79
00:08:15,435 --> 00:08:21,442
key so this will save it. As a text, or as
Ascii formatted text. And now, once I've

80
00:08:21,442 --> 00:08:27,650
done that, I have this file, hello.texas
just appeared on my desktop. And, if I

81
00:08:27,650 --> 00:08:34,022
open this up, you see that this is a text
file with my, with my data saved away. So

82
00:08:34,022 --> 00:08:40,416
that's how you load and save data now
let's talk a bit about how to manipulate

83
00:08:40,416 --> 00:08:46,404
it let's say A = to that matrix again
[sound] so is my 3x2 matrix let's

84
00:08:46,404 --> 00:08:52,879
[inaudible] indexing so if I type A3,2
this indexes into the 3,2 element of the

85
00:08:52,879 --> 00:08:59,920
matrix A so this is like the, this is, you
know and normally we would write this as A

86
00:08:59,920 --> 00:09:05,903
subscript three two or A subscript
[sound]. The 3-2, and so that's the

87
00:09:05,903 --> 00:09:13,993
element in the third row and second column
of A which is the element six. I can also

88
00:09:13,993 --> 00:09:21,915
type a two comma colon to fetch everything
in the second row. So the colon Means,

89
00:09:22,313 --> 00:09:29,343
every element. Along that row or column.
So AF2 colon, comma colon is this second

90
00:09:29,343 --> 00:09:35,312
row of A, right? And similarly if I do A
colon comma two, then this means get

91
00:09:35,312 --> 00:09:41,759
everything in the second column of A. So
this gives me two four six, right? This

92
00:09:41,759 --> 00:09:48,445
means of A everything comma second column.
So this is my second column of A, which is

93
00:09:48,445 --> 00:09:53,679
two four six. Now, you might say use
somewhat more sophisticated indexing

94
00:09:53,679 --> 00:09:59,088
operations. So [inaudible] I'll just
quickly show you an example. You do this

95
00:09:59,088 --> 00:10:04,355
maybe less often, but let me do A, one,
three, comma, colon. This means get all

96
00:10:04,355 --> 00:10:10,049
the elements of a, who's first index is
103. This means I get everything from the

97
00:10:10,049 --> 00:10:16,146
first and third rows of a and from all .
Columns, so this was the matrix A, and so

98
00:10:16,146 --> 00:10:21,584
A, one, three, comma, colon, means get
everything from the first row and from the

99
00:10:21,584 --> 00:10:27,164
second row and, and from the third row.
And colon means you know, I want both the

100
00:10:27,164 --> 00:10:32,248
first and the second columns and so this
gives me this one, two, five, six.

101
00:10:32,248 --> 00:10:37,757
Although you, you use these sorts of more
sophisticated indexing options maybe

102
00:10:37,757 --> 00:10:43,979
somewhat less often. To show you what else
we're going to do here's the A matrix and

103
00:10:43,979 --> 00:10:49,540
that this was A: ,two gave me the second
column you can also use this to do

104
00:10:49,540 --> 00:10:55,476
assignments so I can take the second
column of A and assign that to ten eleven

105
00:10:55,476 --> 00:11:01,333
twelve and if I do that. I'm now, you
know, taking the second column of A and

106
00:11:01,333 --> 00:11:07,214
I'm assigning this column vector ten,
eleven, twelve to it. So now, A is this

107
00:11:07,214 --> 00:11:13,254
matrix, that's one, three, five and the
second column has been replaced by ten,

108
00:11:13,254 --> 00:11:19,373
eleven, twelve. And here's another
operation, it's A, let's, let's set A to

109
00:11:19,373 --> 00:11:25,334
be equal to A comma, 100, 101, 102, like
so. And what this will do, is append

110
00:11:25,334 --> 00:11:35,300
another. Call in vector to the rate. So
now. Oops, I think I made a mistake.

111
00:11:35,920 --> 00:11:45,598
Should I put semicolons there. And now. A
is = to this, okay? I hope that makes

112
00:11:45,598 --> 00:11:50,960
sense. So, this 100, 101, 102, this is a
column vector. And what we did was, we

113
00:11:50,960 --> 00:11:56,323
said, A, take A, and set it to the
original definition. And then we put that

114
00:11:56,323 --> 00:12:02,053
[inaudible] vector to the right. And so
ended up taking the matrix A, and which

115
00:12:02,053 --> 00:12:08,150
was, this, these six elements on the left.
So we took the matrix A, and we appended

116
00:12:08,150 --> 00:12:13,880
another column vector to the right, which
is now why, now A is A, three by three

117
00:12:13,880 --> 00:12:20,454
matrix, it looks like that. And finally
when we [inaudible] I sometime use if we

118
00:12:20,454 --> 00:12:27,232
do A and then just a colon like so.
[inaudible] special case [inaudible]. What

119
00:12:27,232 --> 00:12:34,625
this means is that put all elements of A
into a single column vector and this gives

120
00:12:34,625 --> 00:12:41,666
me a nine by one vector [inaudible] all
the elements of A concatenated together.

121
00:12:41,930 --> 00:12:48,971
Just couple of more examples I can also,
let's see. Let's say I set A to be equal

122
00:12:48,971 --> 00:12:56,330
to One two three four five six okay and
let's say I said B is = to eleven twelve,

123
00:12:56,330 --> 00:13:03,158
thirteen fourteen fifteen sixteen. I can
create a new matrix C. As AB. This just

124
00:13:03,158 --> 00:13:09,803
means. So here's my matrix A, here's my
matrix B and another set C to be equal to

125
00:13:09,803 --> 00:13:15,784
AB. When I'm doing [inaudible]
concatenating them onto each other. So the

126
00:13:15,784 --> 00:13:22,429
left, the matrix A on the left and I have
the matrix B on right and that's how I

127
00:13:22,429 --> 00:13:29,489
form this, you know just make sure it's a
C by putting them together. I can also do

128
00:13:29,489 --> 00:13:35,448
C equals a semicolon B. The semicolon
notation means that means I go put the

129
00:13:35,448 --> 00:13:40,320
next thing at bottom. So [inaudible]
semicolon [inaudible]. It also puts

130
00:13:40,320 --> 00:13:45,947
[inaudible] A and B together expect that
it now puts them on top of each other. So

131
00:13:45,947 --> 00:13:51,337
now I have A on top. And B at the bottom
and, C here, is now a six by two matrix.

132
00:13:51,337 --> 00:13:56,670
So, so, just saying, the semi-colon thing
usually means, you know, go to the next

133
00:13:56,670 --> 00:14:02,142
line. So, C is comprised by A, and go to
the bottom of that and then put B at the

134
00:14:02,142 --> 00:14:07,337
bottom. And, by the way, this AB is the
same as A, B and so, you know, either of

135
00:14:07,337 --> 00:14:12,750
these [inaudible] use the same result. So
with that hopefully you now know how to

136
00:14:12,944 --> 00:14:18,053
construct matrices and hopefully this
slide show, show you some of the commands

137
00:14:18,053 --> 00:14:23,486
that you can use to quickly put together
matrices and take matrices and you know

138
00:14:23,486 --> 00:14:28,206
slam them together and form bigger
matrices, and with just a few lines of

139
00:14:28,206 --> 00:14:33,315
code, Octave is very convenient in terms
of how quickly we can assemble complex

140
00:14:33,315 --> 00:14:39,020
matrices and move data around. So that's
it for moving data around in the next

141
00:14:39,020 --> 00:14:44,620
video we'll start to talk about how to
actually do complex computations on this,

142
00:14:44,620 --> 00:14:50,865
on our data. So hopefully that gets you a
sense of. How, with just a few commands,

143
00:14:50,865 --> 00:14:54,887
you can very quickly move data around in
Octave. You know, those [inaudible]

144
00:14:54,887 --> 00:14:59,016
vectors and matrices, [inaudible] say
data. Put together matrices to create

145
00:14:59,016 --> 00:15:03,199
bigger matrices, index into or select
specific elements of the matrices. I know

146
00:15:03,199 --> 00:15:07,275
I went through a lot of commands. So I
think the best thing for you to do is,

147
00:15:07,436 --> 00:15:11,726
afterward, to look at the transcript of
the things I was typing. You know, look at

148
00:15:11,726 --> 00:15:15,962
the, look at the [inaudible] website, and
download the transcript of the session

149
00:15:15,962 --> 00:15:20,199
from there. And, look for the transcript,
and type some of those commands into

150
00:15:20,199 --> 00:15:24,234
Octave yourself, so that you can start
[inaudible] command. And then again to

151
00:15:24,234 --> 00:15:28,396
work. And obviously there's no point at
all to try to memorize all these commands.

152
00:15:28,396 --> 00:15:33,110
It's just. But, what you should do, is,
hopefully from this video, you have gotten

153
00:15:33,110 --> 00:15:37,537
a sense of the sorts of things you could
do. So that, when, later on, when you're

154
00:15:37,537 --> 00:15:41,965
to program a learning algorithm yourself,
if you are trying to find a specific

155
00:15:41,965 --> 00:15:46,562
command that maybe you think Octave can
do, because you think you might have seen

156
00:15:46,562 --> 00:15:50,990
it here. Should refer to the, to the
transcript of this session, and look for

157
00:15:50,990 --> 00:15:55,417
that, in order to find the commands you
wanna use. So, that's it for moving data

158
00:15:55,417 --> 00:15:59,958
around. And in the next video, what I'd
like to do is [inaudible] to tell you how

159
00:15:59,958 --> 00:16:04,446
to actually do complex computations on our
data, and. Of how to compute some of the

160
00:16:04,446 --> 00:16:07,366
data and actually start to implement
learning algorithms.
