Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,510 --> 00:00:04,700
Hello everyone and welcome to the lecture on our matrix exercise solutions.
2
00:00:04,710 --> 00:00:06,950
Walk through in this lecture video.
3
00:00:06,990 --> 00:00:11,760
I'm going to be going over the solutions for the Art Matrix exercises and explaining as we go along
4
00:00:11,780 --> 00:00:12,040
.
5
00:00:12,300 --> 00:00:14,530
Let's jump to our studio and get started.
6
00:00:14,940 --> 00:00:15,210
OK.
7
00:00:15,210 --> 00:00:16,810
So here we are our studio.
8
00:00:16,830 --> 00:00:21,210
I want to hit him just showing the scripting and the cons. windows.
9
00:00:21,210 --> 00:00:26,850
The first question or exercise we had to perform was to create two vectors and B were A's 1 2 3 and
10
00:00:26,850 --> 00:00:28,490
B is 4 5 6.
11
00:00:28,680 --> 00:00:34,440
Those vectors we had to use the C binder are Byne functions create a two by three Matrix from the vectors
12
00:00:34,940 --> 00:00:38,990
and we'll need to figure out which of these binding functions is the correct choice.
13
00:00:39,000 --> 00:00:41,900
Let's go ahead and get started.
14
00:00:42,030 --> 00:00:49,230
Well go ahead and assign a and we use the combined function that's the lowercase c and we'll do a similar
15
00:00:49,800 --> 00:00:53,700
process for creating B 4 5 6.
16
00:00:54,450 --> 00:00:59,240
And then what we had to do is figure out whether to use C bind or bind.
17
00:00:59,400 --> 00:01:04,400
So what's the actual difference here number that see Byne will bind columns together.
18
00:01:04,560 --> 00:01:12,090
So if we did see binds we would have a result that is a three by two Matrix and the instructions asked
19
00:01:12,090 --> 00:01:13,530
for a two by three.
20
00:01:13,630 --> 00:01:20,010
I mean the correct answer was to use our bind AB.
21
00:01:20,310 --> 00:01:23,000
And here we have our matrix.
22
00:01:23,100 --> 00:01:25,080
Let's go ahead and move on to exercise.
23
00:01:25,080 --> 00:01:27,290
Question number two.
24
00:01:27,600 --> 00:01:33,100
Exercise 2 was to create a three by three matrix consisting of the numbers 1 through 9.
25
00:01:33,240 --> 00:01:35,750
We had to create this met matrix using the shortcut.
26
00:01:35,810 --> 00:01:42,080
One call and nine is by specifying the n row argument in the matrix function call.
27
00:01:42,120 --> 00:01:44,630
Let's assign this matrix the variable M-80.
28
00:01:44,630 --> 00:01:47,520
Matt when you go ahead and clear the con..
29
00:01:48,120 --> 00:01:51,390
So just a quick reminder of what the actual shortcut looks like.
30
00:01:51,390 --> 00:01:56,730
This one Colan nine that creates a sequence of integers.
31
00:01:56,730 --> 00:02:03,330
So for example instead of having to write the combined function one two three for a continuous sequence
32
00:02:03,330 --> 00:02:06,830
of integers I can just say one colon three.
33
00:02:06,900 --> 00:02:14,040
And the syntax is your starting integer colon to your ending last in the integer.
34
00:02:14,070 --> 00:02:21,840
So how do we actually use this with the Matrix call or we're going to say matrix function will pass
35
00:02:21,930 --> 00:02:32,070
in one call in nine and then we're going to say by RHO equals true and we'll say number of rows is equal
36
00:02:32,070 --> 00:02:33,000
to 3.
37
00:02:33,180 --> 00:02:38,130
In order to have it be a three by three it's go to check to make sure that looks correct.
38
00:02:38,160 --> 00:02:40,430
One two three four five six seven eight nine.
39
00:02:40,620 --> 00:02:41,570
Everything's looking good.
40
00:02:41,580 --> 00:02:46,130
Let's go in and save that to the variable M-80.
41
00:02:46,130 --> 00:02:50,300
So I'll take that same command and I will sign it to the variable Max.
42
00:02:50,880 --> 00:02:53,160
And that's how we answer that question.
43
00:02:53,220 --> 00:02:53,900
A quick note.
44
00:02:53,940 --> 00:02:58,070
If you didn't specify by rote the equal true that's OK as well.
45
00:02:58,080 --> 00:03:06,180
So if he did something like this and ran that that would give you filled out by the columns which is
46
00:03:06,180 --> 00:03:09,270
also an acceptable answer doesn't really matter.
47
00:03:09,270 --> 00:03:13,890
You don't do by RHO true since it wasn't specified for this particular question.
48
00:03:13,920 --> 00:03:17,090
Let's go ahead and move on to the next question.
49
00:03:17,100 --> 00:03:17,430
All right.
50
00:03:17,430 --> 00:03:21,320
Question number three was to confirm that M-80 variable is a matrix.
51
00:03:21,360 --> 00:03:23,290
Using is dot matrix.
52
00:03:23,340 --> 00:03:27,910
Let me go and explain how that is that Matrix actually works.
53
00:03:28,050 --> 00:03:29,420
I'm going to say is dots.
54
00:03:29,490 --> 00:03:35,160
And you'll notice our studio will actually have a huge drop down menu of all the things we can check
55
00:03:35,180 --> 00:03:35,450
.
56
00:03:35,670 --> 00:03:41,220
So the is the methods are really useful if you're trying to check what data type data structure you're
57
00:03:41,220 --> 00:03:42,140
working with.
58
00:03:42,210 --> 00:03:45,670
Then in this case we're going to go ahead and check if something is a matrix.
59
00:03:45,870 --> 00:03:52,320
So you end up doing is say is that matrix and you pass in the variable you want to check and it'll return
60
00:03:52,320 --> 00:04:00,720
true because the M-80 variable is a matrix and you can actually use the same sort of operation for any
61
00:04:00,720 --> 00:04:01,360
data type.
62
00:04:01,350 --> 00:04:06,780
So if I go in and clear the console and say Is dots we can check if something is an array.
63
00:04:06,960 --> 00:04:14,400
So we can go ahead and pass in MIT and we get true in this case because Matrix's do count as a form
64
00:04:14,400 --> 00:04:15,720
of an array.
65
00:04:15,730 --> 00:04:17,960
Notice an array is not the same as a vector.
66
00:04:18,180 --> 00:04:20,860
You can think of a matrix as just a two dimensional array.
67
00:04:21,030 --> 00:04:28,590
But if we do something like check is dot for instance data frame which will learn about in more detail
68
00:04:28,590 --> 00:04:34,640
later we pass and met we get false because a matrix and a data frame aren't the same thing.
69
00:04:34,650 --> 00:04:38,710
Let's go ahead and move on to the next question.
70
00:04:38,710 --> 00:04:44,460
Number four exercise for was to create a five by five matrix consisting of the numbers 1 through 25
71
00:04:44,820 --> 00:04:50,090
and assign it to the variable M-80 2 and the top row should be the numbers 1 through 5.
72
00:04:50,400 --> 00:04:54,690
So we're going to do this really Similarly it's how we just did the last Matrix.
73
00:04:54,690 --> 00:05:01,200
I'm going to go ahead and say Matt 2 for my variable name and then I will pass in the matrix function
74
00:05:01,200 --> 00:05:01,790
.
75
00:05:02,090 --> 00:05:07,730
I'll use that shortcut to quickly create a vector one through 325.
76
00:05:07,740 --> 00:05:12,900
Notice it said the top row should be the numbers 1 through 5 meaning I want to fill this out by rows
77
00:05:12,900 --> 00:05:14,140
not by columns.
78
00:05:14,160 --> 00:05:18,200
So since my columns is the default meaning by rows is false.
79
00:05:18,210 --> 00:05:22,920
And I go ahead and say by row capital-T for true.
80
00:05:23,120 --> 00:05:26,370
And then finally I want this to be a five by five matrix.
81
00:05:26,370 --> 00:05:29,150
So I want the number of rows to be five.
82
00:05:29,610 --> 00:05:31,790
Let's go ahead and check that too.
83
00:05:32,490 --> 00:05:33,840
It looks like everything worked well.
84
00:05:33,840 --> 00:05:37,940
We have a five by five Matrix and we have one two three four five.
85
00:05:38,520 --> 00:05:42,420
OK moving on to the next question using indexing notation.
86
00:05:42,450 --> 00:05:50,370
Grab a subsection of Matt 2 from the previous exercise that looks like this 7 comma 8 12 comma 13.
87
00:05:50,370 --> 00:05:52,390
All right let's go ahead and do that.
88
00:05:52,710 --> 00:05:58,830
So let's go in and locate where 7 8 12 13 would be in or M8 to are meant to object.
89
00:05:58,830 --> 00:06:03,510
Looks like it's 78 right here in columns 2 and 3 wrote 2.
90
00:06:03,810 --> 00:06:08,530
And then we also have in the same columns 2 and 3 but row 3 total 13.
91
00:06:08,700 --> 00:06:12,480
So essentially want to grab this square chunk out of our matrix.
92
00:06:12,780 --> 00:06:16,020
Let's go ahead and do that well you use bracket notation.
93
00:06:16,020 --> 00:06:18,750
Or the indexing notation that we learned earlier.
94
00:06:18,750 --> 00:06:25,500
First thing I want to do is pass in the rows that I want in this case I want rows two through three
95
00:06:25,500 --> 00:06:26,290
.
96
00:06:26,490 --> 00:06:32,850
So one way I can do that is just by using that colon rotation rows two three three and actually want
97
00:06:32,850 --> 00:06:34,360
this exact same columns.
98
00:06:34,450 --> 00:06:42,750
So say comma exactly mutation and if I run that we get that result 7 8 12 13 to enter two times it goes
99
00:06:42,750 --> 00:06:43,490
up a bit.
100
00:06:43,610 --> 00:06:45,210
But here it is.
101
00:06:45,210 --> 00:06:47,600
So this is the correct way that index for that.
102
00:06:48,090 --> 00:06:54,450
Let's move on to the next exercise which is also an index notation exercise and for this exercise we
103
00:06:54,450 --> 00:07:01,620
want it to again grab a subsection that now looks like this 19 20 and 24 25.
104
00:07:01,860 --> 00:07:10,140
Looking again at our math to object we have 19 20 and 24 25 looks like that's a two by two subsection
105
00:07:10,650 --> 00:07:14,470
in rows and columns 4 5 and 4 5.
106
00:07:14,910 --> 00:07:15,780
So how do we do this.
107
00:07:15,780 --> 00:07:17,510
Well again it's going to be really similar.
108
00:07:17,520 --> 00:07:21,190
Hopefully if he did the last one you'll be able to answer this one as well.
109
00:07:21,240 --> 00:07:24,000
We're going in clear the councils we have in a Froom.
110
00:07:24,120 --> 00:07:27,010
I'll say I'm at 2 again so you can see it.
111
00:07:27,330 --> 00:07:30,960
I want 19 20 and 24 25.
112
00:07:30,960 --> 00:07:38,280
So again pass met to a pass in the rows that I want which is rows 4 through 5.
113
00:07:38,640 --> 00:07:43,610
And then I pass the columns I want which again is Aurthur 5.
114
00:07:43,860 --> 00:07:47,280
And there we have that subsection in the matrix.
115
00:07:47,280 --> 00:07:52,200
As mentioned during the matrix lectures it's really useful if you're struggling with this concept of
116
00:07:52,560 --> 00:08:00,070
rows common columns to just in your mind grab subsections of the matrix and then try to index them.
117
00:08:00,360 --> 00:08:02,310
So do a quick example of this.
118
00:08:02,310 --> 00:08:08,190
In case you're struggling this concept let's say I wanted to grab seven eight nine ten and then 12 13
119
00:08:08,190 --> 00:08:08,940
14 15.
120
00:08:08,940 --> 00:08:10,580
So a rectangular Matrix.
121
00:08:10,830 --> 00:08:19,690
Well I just identify the rows that I want so two three and it passes into Colon three and then identify
122
00:08:19,710 --> 00:08:22,340
the columns I want which is two three four five.
123
00:08:22,350 --> 00:08:28,140
So let's to call in five and I get this answer as a result.
124
00:08:28,140 --> 00:08:30,420
Again that's not an actual exercise question in this case.
125
00:08:30,420 --> 00:08:33,530
Just an example of how you can break this problem down.
126
00:08:33,570 --> 00:08:38,970
So if you're struggling with this make sure you practice it a lot just by choosing subsections and trying
127
00:08:38,970 --> 00:08:40,130
to get them out.
128
00:08:40,620 --> 00:08:45,180
Let's go to move on to the next exercise which was exercise 7.
129
00:08:45,210 --> 00:08:49,400
The question was What is the sum of all the elements in Mat 2.
130
00:08:49,530 --> 00:08:50,930
How do we actually do that.
131
00:08:51,210 --> 00:08:59,960
Well you can clear the console and we just use the sum function so we can say some math too.
132
00:09:01,050 --> 00:09:06,210
So hopefully to discover that if you just say some math to it will sum all the elements.
133
00:09:06,240 --> 00:09:12,630
Quick side note if you're looking to some just the columns or just the rows you can add additional arguments
134
00:09:12,720 --> 00:09:21,840
like call some's or sum up the column so we can go in and say I met two and then row sums.
135
00:09:22,260 --> 00:09:24,520
Works for the rows.
136
00:09:24,660 --> 00:09:24,930
All right.
137
00:09:24,990 --> 00:09:26,360
So those are just quick side notes.
138
00:09:26,370 --> 00:09:33,330
But in this case if you want to do all the elements shust normal some moving on we have one more exercise
139
00:09:33,330 --> 00:09:34,380
.
140
00:09:34,380 --> 00:09:35,460
And it was this.
141
00:09:35,460 --> 00:09:43,320
Find out how to use run I if this function to create a four by five matrix consisting of 20 random numbers
142
00:09:43,920 --> 00:09:46,350
four times five is equal to 20.
143
00:09:46,350 --> 00:09:49,400
All right let's go ahead and see how he would do this.
144
00:09:49,470 --> 00:09:53,610
First thing I'm going to assume that you've never actually seen this function before run.
145
00:09:53,900 --> 00:09:55,260
So I want to find out how to use it.
146
00:09:55,290 --> 00:09:56,970
Meaning I want to help on this.
147
00:09:56,970 --> 00:09:58,010
I'll say help.
148
00:09:58,140 --> 00:09:58,960
And pasan.
149
00:09:59,010 --> 00:10:06,300
Ron I-F and then boom we have a nice help tab here and we see what the arguments look like and what
150
00:10:06,330 --> 00:10:07,170
we should actually do.
151
00:10:07,170 --> 00:10:09,320
So what actually is run I.
152
00:10:09,390 --> 00:10:11,400
Well it's a uniform distribution.
153
00:10:11,520 --> 00:10:15,780
And what that means is these functions essentially provide information with the uniform distribution
154
00:10:15,780 --> 00:10:19,020
from the interval from min to Max.
155
00:10:19,020 --> 00:10:21,250
So how do we actually do this.
156
00:10:21,270 --> 00:10:26,660
We look here and notice we have a few uniform distribution functions.
157
00:10:26,760 --> 00:10:28,390
But the last one here is run.
158
00:10:28,450 --> 00:10:33,030
The one we referred to is a little small so hopefully you can call as far as font size.
159
00:10:33,130 --> 00:10:35,250
You can call help here and that spoiler's yourself.
160
00:10:35,460 --> 00:10:41,430
But if I just go in and copy this so we can see what it's actually saying in the documentation it says
161
00:10:41,520 --> 00:10:45,660
run a f n comma min equals zero Max equals 1.
162
00:10:45,660 --> 00:10:49,800
So those are the parameters or arguments we have to pass into this function and if we check out the
163
00:10:49,800 --> 00:10:54,860
documentation for what it is it says and is a number of observations.
164
00:10:54,870 --> 00:10:58,160
All right so we know we want 20 random numbers.
165
00:10:58,320 --> 00:11:00,970
So that means I want to draw 20.
166
00:11:01,130 --> 00:11:11,410
If I go yes go ahead and say run I if I pass in 20 and looks like it returns a vector of 20 random numbers
167
00:11:11,400 --> 00:11:11,430
.
168
00:11:11,430 --> 00:11:13,040
Perfect.
169
00:11:13,110 --> 00:11:16,800
Now I can also specify min and max value.
170
00:11:17,220 --> 00:11:19,770
So for instance right now I'm just doing random numbers.
171
00:11:19,770 --> 00:11:23,420
Frean the defaults and the defaults were 0 and 1.
172
00:11:23,520 --> 00:11:34,200
But if I go ahead and say run I if it's a random uniform distribution pass in 20 values I can also specify
173
00:11:34,200 --> 00:11:36,710
what I want the min value to be and the Max might be.
174
00:11:36,720 --> 00:11:43,180
So if I wanted to pick numbers tween 0 and 100 I could say many equals zero.
175
00:11:43,470 --> 00:11:46,060
And I could change my max to be 100.
176
00:11:46,470 --> 00:11:55,410
And now I get 25 or 20 random numbers between 0 and 100 in the solutions notebook I show putting in
177
00:11:55,410 --> 00:11:56,660
the men and the max.
178
00:11:56,670 --> 00:11:57,840
You don't actually have to do that.
179
00:11:57,840 --> 00:12:00,920
You could have just run run f 20.
180
00:12:00,960 --> 00:12:05,190
Let's go ahead and go with min and max settings.
181
00:12:05,190 --> 00:12:06,750
So how do we actually perform this.
182
00:12:06,750 --> 00:12:11,100
As far as creating this matrix of a four by five consisting of these when he ran the numbers will you
183
00:12:11,100 --> 00:12:17,820
just say matrix and then we pass in run I f 20
184
00:12:20,490 --> 00:12:28,990
and we wants four rows who want a four by five matrix and there is our matrix.
185
00:12:29,190 --> 00:12:33,670
And notice here even though it's printing out like this is a four by five.
186
00:12:33,830 --> 00:12:36,670
I'm going to go ahead and do is expand the window a bit.
187
00:12:36,720 --> 00:12:41,960
You can always check by what the index locations are the dimensions of your matrix.
188
00:12:41,970 --> 00:12:47,260
But if I run this again then we can see for sure that it's a four by five matrix.
189
00:12:47,310 --> 00:12:52,170
All right mixture of the notebook in case you're confused on anything but remember the main point of
190
00:12:52,170 --> 00:12:58,230
this last question was to get you used to reading help on functions that you don't know about and learning
191
00:12:58,230 --> 00:13:00,080
how to use them.
192
00:13:00,120 --> 00:13:00,980
All right.
193
00:13:01,140 --> 00:13:02,960
Hopefully that wasn't too bad.
194
00:13:02,970 --> 00:13:08,000
Make sure review the matrix lectures in case you're unsure of anything we just covered.
195
00:13:08,220 --> 00:13:09,750
Thanks and I'll see you at the next lecture
19652
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.