All language subtitles for 2. Creating a Matrix

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian Download
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,570 --> 00:00:05,490 Hello everyone and welcome to the Creating a matrix lecture before you learn about the various data 2 00:00:05,490 --> 00:00:06,380 types in our. 3 00:00:06,420 --> 00:00:12,300 And we've also learned about vectors which allow us to store indexed elements matrix is going to allow 4 00:00:12,300 --> 00:00:17,740 us to have to them actual data structures which contain elements consisting of the same data type. 5 00:00:17,760 --> 00:00:22,500 Let's go ahead and jump to our studio to explore how to create a matrix. 6 00:00:22,500 --> 00:00:22,990 OK. 7 00:00:23,040 --> 00:00:24,740 So here are our studio. 8 00:00:24,750 --> 00:00:30,240 And before we actually talk about The Matrix I want to show you a quick tip for quickly creating sequential 9 00:00:30,240 --> 00:00:36,120 numeric vectors you can use the colon notation similar to the slicing notation to actually create a 10 00:00:36,120 --> 00:00:38,540 sequential vector of numerics. 11 00:00:38,550 --> 00:00:47,490 So for example if I go ahead and type into the console one Clinton I get out a vector that sequential 12 00:00:47,580 --> 00:00:51,590 integers that goes from 1 to 10. 13 00:00:51,690 --> 00:00:53,010 So this is a nice trick. 14 00:00:53,160 --> 00:00:57,640 They'll help you save a lot of time when you're creating these sequential numeric vectors. 15 00:00:57,780 --> 00:01:01,380 And then you can assign this to a variable. 16 00:01:01,380 --> 00:01:09,640 So for instance if I do this sort of assignments I've actually created quickly a vector of numeric sequence 17 00:01:09,650 --> 00:01:10,090 . 18 00:01:10,110 --> 00:01:10,530 All right. 19 00:01:10,860 --> 00:01:15,400 So now that we know that little trick that's going to help us a lot with the matrix function. 20 00:01:15,480 --> 00:01:21,430 So to create a matrix and are used the matrix function and the capacitate vector to it. 21 00:01:22,050 --> 00:01:27,090 So I'm going to go in and say matrix and then I'm going to go ahead and pass in the data in this case 22 00:01:27,180 --> 00:01:32,650 the first thing to do is just pass in the vector and we'll slowly discover the other arguments or parameters 23 00:01:32,660 --> 00:01:32,680 . 24 00:01:32,700 --> 00:01:35,710 We can define in the matrix function. 25 00:01:35,810 --> 00:01:40,230 So now you'll notice that I've created a matrix and notice how it's been printed out. 26 00:01:40,320 --> 00:01:42,260 Now it shows that it's in two dimensions. 27 00:01:42,270 --> 00:01:48,520 We have 10 rows with one column instead of just having this one dimensional array. 28 00:01:48,690 --> 00:01:53,520 So the outputs been displayed as a two dimensional matrix which is 10 rows by one column. 29 00:01:53,820 --> 00:01:56,930 But what if we actually want to specify the number of rows. 30 00:01:57,060 --> 00:02:02,850 So we actually want to specify how we construct this two dimensional matrix from that one the array 31 00:02:02,940 --> 00:02:03,750 vector. 32 00:02:03,920 --> 00:02:10,140 But we can pass a parameter arguments into the matrix called and row which stands for the number of 33 00:02:10,140 --> 00:02:10,940 rows. 34 00:02:10,950 --> 00:02:13,880 So let's go ahead and try this again. 35 00:02:13,950 --> 00:02:22,860 I'm going to clear the console check that is still that vector 1 through 10 call the Matrix on V and 36 00:02:22,860 --> 00:02:26,530 I'm going to go ahead and pass in a parameter and row. 37 00:02:26,850 --> 00:02:29,530 And this just stands for the desired number of rows. 38 00:02:29,760 --> 00:02:35,340 So I'm going to go ahead and say I want two rows to be made from this vector. 39 00:02:35,430 --> 00:02:40,920 And so now a matrix has two rows and says we need to have the correct number of columns in order to 40 00:02:40,920 --> 00:02:42,140 equal 10 elements. 41 00:02:42,180 --> 00:02:46,900 It's going to be five columns since five times two is equal to 10. 42 00:02:46,920 --> 00:02:51,010 So now we've been able to specify a two by five matrix. 43 00:02:51,450 --> 00:02:54,960 Notice how the NRA argument allowed that to happen. 44 00:02:55,110 --> 00:03:00,090 But the other question you may have is how do we actually the side that still order we could have filled 45 00:03:00,090 --> 00:03:02,420 the columns first as we did in this case. 46 00:03:02,430 --> 00:03:04,440 One two three four five six. 47 00:03:04,590 --> 00:03:08,170 But we also could have filled the rows in sequential order. 48 00:03:08,190 --> 00:03:13,120 So for example we could have had that first row been one to three four. 49 00:03:13,140 --> 00:03:14,700 The horizontal. 50 00:03:14,700 --> 00:03:18,480 Do you actually want to specify how you filled the matrix. 51 00:03:18,480 --> 00:03:24,600 Default is by columns B you can say and add a by RHO argument which allows you to see whether or not 52 00:03:24,600 --> 00:03:27,170 you want to fill out the Matrix right rows or columns. 53 00:03:27,180 --> 00:03:30,710 So we're going to show you an example of that. 54 00:03:30,760 --> 00:03:39,600 Going to go ahead and say Matrix and instead of passing and V and then the in a vector that goes from 55 00:03:39,600 --> 00:03:50,490 1 to 12 sequentially using that colon notation and then to go ahead and specify by RHO to be equal to 56 00:03:50,940 --> 00:03:53,430 false which is the default case. 57 00:03:53,850 --> 00:03:57,740 And I'm going to specify a number of rows equal to 4. 58 00:03:58,050 --> 00:04:03,390 So I have four rows meaning I should have three columns and four times three is 12. 59 00:04:03,690 --> 00:04:10,820 And since I said biros equal to false which is the default anyways the matrix is filled by column for 60 00:04:10,810 --> 00:04:10,870 . 61 00:04:10,870 --> 00:04:16,120 So notice how that first column that one column here has 1 2 3 4. 62 00:04:16,320 --> 00:04:19,240 And the second column is 5 6 7 8. 63 00:04:19,290 --> 00:04:22,980 Also pay attention to how this index notation actually looks. 64 00:04:22,980 --> 00:04:28,400 With the comma placements versus the rows and columns here. 65 00:04:28,410 --> 00:04:34,440 So in the rows you get the row number first and then the comma and in the columns you get a comma first 66 00:04:34,560 --> 00:04:36,430 and then the column number. 67 00:04:36,720 --> 00:04:44,350 Later on we'll discuss why that's important for index purposes but for now which lushest us the by row 68 00:04:44,370 --> 00:04:48,470 and the end row let's go ahead and try this same operation. 69 00:04:48,630 --> 00:04:52,160 You'll go ahead and say biros is equal to true. 70 00:04:52,320 --> 00:05:00,900 So don't go ahead and press up on my keyboard and change this false to be a capital T for true. 71 00:05:01,190 --> 00:05:01,750 All right. 72 00:05:02,060 --> 00:05:06,050 So now I said biros equal to T for true. 73 00:05:06,140 --> 00:05:11,180 And I've been able to fill out this matrix by the row first so one two three four five six seven eight 74 00:05:11,180 --> 00:05:12,500 nine etc.. 75 00:05:13,120 --> 00:05:18,410 Now that we've gone over some of the basics of using the matrix function and the additional parameters 76 00:05:18,410 --> 00:05:23,740 inside of it let's go over how we can create matrices from many vectors and then how we can actually 77 00:05:23,750 --> 00:05:25,530 name matrices. 78 00:05:25,550 --> 00:05:30,230 So in order to do this I'm actually going to start writing in our scripts so to bring down the cancelbot 79 00:05:30,920 --> 00:05:34,710 and type into this demo the script that I have here. 80 00:05:34,750 --> 00:05:41,650 Let's go ahead and create two vectors one called g g which will go ahead and pretend that we're working 81 00:05:41,660 --> 00:05:43,920 with stock prices for Google. 82 00:05:43,940 --> 00:05:46,640 These aren't real prices I'm just making them up. 83 00:05:47,340 --> 00:05:52,450 Well let's say we have just a steady rise maybe a little bit of a fall. 84 00:05:52,510 --> 00:05:58,180 So just five stock prices for the five work days going to go ahead and make that into a vector. 85 00:05:58,340 --> 00:06:05,120 Now let's make one more for let's say Microsoft and let's just go ahead and make up some stock prices 86 00:06:05,120 --> 00:06:08,730 . 87 00:06:08,740 --> 00:06:09,340 All right. 88 00:06:09,710 --> 00:06:20,030 So we have two vectors and we can actually combine these into an object called or a variable called 89 00:06:20,020 --> 00:06:20,740 stocks 90 00:06:25,190 --> 00:06:29,100 and we'll use the combined function in this manner. 91 00:06:29,120 --> 00:06:33,980 So now I have my two vectors Google and Microsoft and I'm using the combined function by passing them 92 00:06:33,980 --> 00:06:37,270 in Google Microsoft and then I'm calling that variable stocks. 93 00:06:37,390 --> 00:06:44,150 If I go ahead and say on line 6 to the space stocks and then I'm going to go ahead and run this file 94 00:06:44,140 --> 00:06:45,860 here. 95 00:06:45,860 --> 00:06:49,120 Notice that now in our environment we have this stock's value. 96 00:06:49,190 --> 00:06:55,640 And if I want to see it in the console and I can actually just say print stocks so it's going to run 97 00:06:55,630 --> 00:06:57,420 that so we can see it in the con.. 98 00:06:57,710 --> 00:07:01,120 And notice I have 450 4:31 the Google prices. 99 00:07:01,340 --> 00:07:04,370 And then I got it combined with the Microsoft prices. 100 00:07:04,460 --> 00:07:08,960 So if I actually want to build a matrix out of this I can use the following notation. 101 00:07:08,960 --> 00:07:13,520 I can say stock Matrix 102 00:07:16,060 --> 00:07:24,610 is the matrix function and I can pass in stocks than say by RHO is equal to. 103 00:07:24,640 --> 00:07:26,790 Let's go ahead and just say T for true. 104 00:07:27,620 --> 00:07:32,470 And then I'm going to specify and RHO to be equal to the number two. 105 00:07:32,530 --> 00:07:38,540 So I'm going to say and a row is equal to two. 106 00:07:39,080 --> 00:07:46,090 And let's go ahead and then just printout that stock matrix to see what it looks like. 107 00:07:46,100 --> 00:07:49,240 So it's from that source. 108 00:07:49,250 --> 00:07:54,940 And now we can see here we have this nice little matrix where the first row represents those Google 109 00:07:54,950 --> 00:07:55,950 stock prices. 110 00:07:56,000 --> 00:08:00,470 And the second row represents those Microsoft stock prices. 111 00:08:00,470 --> 00:08:05,570 And now we want to do since we have our nice matrix it actually be nice to name the rows and the columns 112 00:08:05,560 --> 00:08:11,480 for reference and we can actually do this just like we did it for vectors using the names function but 113 00:08:11,480 --> 00:08:17,560 instead of using names we're going to do is use call names and row names in order to specify whether 114 00:08:17,840 --> 00:08:20,040 naming the columns or the rows. 115 00:08:20,060 --> 00:08:24,190 So let's go ahead and work on that part. 116 00:08:24,250 --> 00:08:25,600 So we have that stock matrix. 117 00:08:25,610 --> 00:08:26,730 Let's go ahead and name it. 118 00:08:26,930 --> 00:08:32,030 It's going to be really similar to the way we named the vectors except we have two functions call names 119 00:08:32,020 --> 00:08:32,810 and row names. 120 00:08:32,840 --> 00:08:38,210 Now we have two that mentions Let's go ahead and make a vector called days. 121 00:08:38,210 --> 00:08:48,640 And we're just going to have it be the days of the week so say Monday Tuesday Wednesday Thursday and 122 00:08:48,640 --> 00:08:49,170 Friday 123 00:08:53,210 --> 00:08:59,160 and then we'll also have let's say stock names. 124 00:08:59,990 --> 00:09:07,170 And those are going to be equal to just their tickers which is Google and then MSFC Microsoft. 125 00:09:07,460 --> 00:09:13,670 So have these two vectors which are the names you want and then we're going to go ahead and do is use 126 00:09:13,730 --> 00:09:18,340 the name functions so call names in our stock matrix 127 00:09:21,190 --> 00:09:33,250 and then assign it with days and then similarly foreign names pasand stock matrix and assign it those 128 00:09:33,280 --> 00:09:34,810 ST names. 129 00:09:34,820 --> 00:09:35,780 All right. 130 00:09:35,780 --> 00:09:41,240 And then once you've done that let's go ahead and just print out the stock matrix and see what it looks 131 00:09:41,240 --> 00:09:42,190 like. 132 00:09:42,230 --> 00:09:44,160 So it's going to run that source. 133 00:09:44,870 --> 00:09:50,690 And notice now we have a really nice looking matrix here in the console we have the columns clearly 134 00:09:50,680 --> 00:09:56,180 defined by the days of the week and then the rows clearly names for their stock ticker. 135 00:09:56,200 --> 00:09:57,520 They refer to. 136 00:09:57,620 --> 00:09:58,170 All right. 137 00:09:58,510 --> 00:10:02,770 So it looks like we're really starting to build up a powerful tool that we can use later on. 138 00:10:02,990 --> 00:10:07,790 And you should begin to be reminded of a spreadsheet later on we're going to learn about data frames 139 00:10:07,880 --> 00:10:10,830 another data structure is going to build on top of this idea. 140 00:10:11,000 --> 00:10:15,470 For now that's the basics of actually creating a matrix in the next structure we're going to be building 141 00:10:15,470 --> 00:10:17,380 off this matrix of stock prices. 142 00:10:17,410 --> 00:10:20,340 So go ahead and keep this code for future reference. 143 00:10:20,360 --> 00:10:20,980 Okay. 144 00:10:21,130 --> 00:10:23,020 Thanks everyone and I'll see you at the next lecture 14904

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.