WEBVTT 00:01.600 --> 00:08.320 Malcolm in his lecture, I'm going to talk about arrays of arrays or in other words, multidimensional 00:08.320 --> 00:08.790 arrays. 00:09.430 --> 00:14.380 So a multidimensional array is an ordinary array that contains other arrays. 00:14.800 --> 00:16.000 Let me show you an example. 00:17.630 --> 00:25.520 Imagine that there are two areas like these, once this area literally create these areas, each one 00:25.520 --> 00:28.880 stores the last three grades of two students. 00:29.750 --> 00:30.200 All right. 00:30.410 --> 00:37.160 Now I'm going to create a multidimensional array by using these areas here to create a multidimensional 00:37.160 --> 00:37.610 area. 00:37.670 --> 00:40.610 I'm going to use an area literal such as this one. 00:42.210 --> 00:44.080 I'll explain this syntax shortly. 00:44.140 --> 00:50.580 No worries, so these are literal creates a multidimensional array like this one, you can think of 00:50.580 --> 00:57.780 this as an array of arrays or as a table or as a matrix from math and so on. 00:58.410 --> 01:04.560 Outer area contains the inner arrays and its type looks like this. 01:04.770 --> 01:09.270 It is two elements of three integer arrays, OK? 01:09.660 --> 01:13.170 The first row here contains the first inner array. 01:14.530 --> 01:17.470 And the second row contains the second Inotera. 01:19.340 --> 01:25.410 You can access to the first Inotera by using the first index of the outer area. 01:25.670 --> 01:26.080 OK. 01:27.250 --> 01:32.900 And you can access the second in L.A. by using the second index of the outer. 01:35.710 --> 01:43.510 As you know, this highlighted part describes the area's length, so this area should only contain two 01:43.510 --> 01:44.380 inner areas. 01:45.130 --> 01:51.130 However, as you know, you can change this to any length at the compile time, of course. 01:53.830 --> 02:00.760 As you also know, this is the element type of the area, it determines the type of injuries this can 02:00.760 --> 02:01.450 be anytime. 02:01.870 --> 02:06.610 This is actually just a type this is just one element I do not think of. 02:06.610 --> 02:07.690 It is something else. 02:07.900 --> 02:11.220 This is the same thing that we have learned in the previous lectures. 02:11.260 --> 02:11.620 OK. 02:13.030 --> 02:19.450 So these are the types of injuries, for example, here, all the injuries have the same types, right, 02:20.230 --> 02:25.420 is because the parents Herries type or the outrace type is also through injury. 02:26.140 --> 02:31.270 So in a multidimensional way, you can only store injuries with the same types. 02:32.230 --> 02:34.960 By the way, is golems simplistic. 02:35.260 --> 02:36.780 Let me show you one more thing. 02:37.930 --> 02:45.650 Gore knows that the errors here have the same types, right, it knows it from the outer erase element. 02:46.510 --> 02:51.100 So Gore allows you to omit the types for the inner errors altogether. 02:51.910 --> 02:55.100 This error, literal syntax, is the same as the previous one. 02:55.690 --> 02:57.840 So it creates the very same error. 02:58.540 --> 03:02.020 So you can Ormet the types Gore implicitly adds down for you. 03:04.330 --> 03:07.630 Now, I'm going to show you a few examples inside the court, Ed. 03:11.080 --> 03:15.440 Our goal is to find the average grade of all the given students. 03:15.470 --> 03:15.780 OK. 03:16.910 --> 03:19.330 So now I'm going to create, to erase. 03:20.650 --> 03:27.010 This one is for the first students grades and this one is for the second students grades. 03:27.980 --> 03:33.560 I declared these areas using flawed six to four because I don't want to convert them again in the rest 03:33.560 --> 03:34.160 of the court. 03:34.190 --> 03:35.470 OK, you will see about it. 03:36.720 --> 03:42.270 So I want to calculate the average grade, so now I'm going to declare a flawed six to four variable, 03:43.060 --> 03:46.800 then I'm going to sum all the grades of the first student like this. 03:49.620 --> 03:52.590 Don, I'm going to do the same thing for a second student as. 03:53.520 --> 03:59.390 OK, now I've calculated the total grades for every student to find out the average. 03:59.400 --> 04:03.240 I need to divide this into the total number of grades. 04:03.510 --> 04:03.880 Right. 04:04.560 --> 04:09.180 Let's find out the total number of grades that I'm going to declare a constant here. 04:10.510 --> 04:17.420 Remember when you used the land function with an error, it returns a constant integer and I have used 04:17.440 --> 04:24.460 a constant here also because constants are compile time values, unlike variables, they don't allocate 04:24.460 --> 04:25.720 new memory space. 04:26.500 --> 04:29.580 So now I'm going to get the length of the first student. 04:29.920 --> 04:34.000 This will work because each student has the same number of grades. 04:34.390 --> 04:38.590 Then I'm going to multiply it with two because there are two students. 04:39.280 --> 04:40.600 OK, let me print it. 04:42.130 --> 04:47.260 Here, I need to divide the total grades with the total number of grades like this. 04:48.100 --> 04:56.410 However, there is a type mismatch here, this land function returns an end, whereas the same variable 04:56.410 --> 04:57.910 is a flawed six to four. 04:58.510 --> 05:04.030 So it is better to convert it here in this constant because I may need it again. 05:04.280 --> 05:07.380 It's better to convert it once now. 05:07.390 --> 05:07.840 It's OK. 05:08.060 --> 05:10.090 Let me run this school. 05:10.360 --> 05:12.670 The average grade is 5.5. 05:13.100 --> 05:16.010 However, as you know, this is not good. 05:16.780 --> 05:22.780 Think about what would happen if I need to find out the average grade of ten students instead. 05:23.650 --> 05:26.200 So let me comment about this quote entirely. 05:27.260 --> 05:33.710 Instead of doing it like this, let's use a multidimensional array, let's call it students. 05:34.710 --> 05:41.160 Now I'm going to declare the areas land first, there will be two students, so the areas should be 05:41.160 --> 05:42.070 two or not. 05:42.690 --> 05:46.570 I'm going to start fallowed six to four areas with three elements in this area. 05:47.250 --> 05:50.130 So now I'm going to type three floors, six to four here. 05:51.090 --> 05:53.230 Now I need to give it a rest. 05:53.820 --> 05:59.400 Here are the grades of the first student and here are the second students grades, then I'm going to 05:59.400 --> 06:02.190 sum all the grades by hand like this. 06:02.220 --> 06:03.950 Let's do that for the first student. 06:04.350 --> 06:08.460 First, I'm going to get the first student from the altar of students like this. 06:09.270 --> 06:10.720 This returns the first error. 06:11.400 --> 06:16.260 Then let's get the grades of the first student by using the returned array. 06:16.920 --> 06:20.130 Then let's get the second and the third grades of the first student. 06:22.180 --> 06:22.600 OK. 06:23.510 --> 06:26.590 And lastly, let's do the same thing for the second student. 06:27.410 --> 06:33.410 OK, this time index is one, so it returns the second student's grace. 06:33.800 --> 06:38.000 OK, now let's calculate the total number of grades again. 06:38.210 --> 06:40.970 Let's first convert it to offload 64. 06:41.660 --> 06:44.900 Then here I'm going to get the total number of students first. 06:45.530 --> 06:49.380 These returns two, because there are two inner errors in the students. 06:49.760 --> 06:56.090 OK, then I'm going to multiply this with the total number of grades for the first student like this 06:56.660 --> 06:59.160 since all the inner arrays have the same length. 06:59.630 --> 07:02.360 So using the first student here is enough. 07:02.750 --> 07:05.200 I could have used the second student as well. 07:05.420 --> 07:06.080 Doesn't matter. 07:06.920 --> 07:09.980 All right, now let's print the average grade like this. 07:11.390 --> 07:12.890 All right, let me read on it. 07:13.940 --> 07:20.030 The result is the same cool now you know how to get the elements from a multidimensional array. 07:20.310 --> 07:23.010 However, this isn't good either. 07:23.870 --> 07:27.670 Now let's do it for the last time in the best way possible. 07:28.650 --> 07:34.800 So now let me duplicate this quote first and let me comment about this previous quote here, OK? 07:35.590 --> 07:38.790 As you learn, you don't need to type the types here. 07:39.450 --> 07:42.960 Go knows about it already from the terrorist elements. 07:43.560 --> 07:45.860 So now I'm going to remove them altogether. 07:46.500 --> 07:51.820 I also don't need to describe the areas that go can also find it on its own. 07:52.410 --> 07:55.290 So now I'm going to change it to the ellipses like this. 07:55.680 --> 07:56.220 All right. 07:56.230 --> 07:59.310 Better than I'm going to delete this quote here. 08:00.350 --> 08:01.790 They are not necessary anymore. 08:01.820 --> 08:04.170 You're going to see it in a second, why here? 08:04.190 --> 08:05.120 I'm going to range over. 08:05.120 --> 08:06.580 The students are like this. 08:07.220 --> 08:11.120 So this great variable is going to store each one of the inner arrays. 08:11.630 --> 08:15.690 I need to sum all the grades, so I need another loop here. 08:16.400 --> 08:19.550 Now, I'm going to range over this great variable like this. 08:21.300 --> 08:26.700 You know, its type is three floors, six to far right, so its doors and Internet. 08:27.660 --> 08:32.610 Now I'm going to add the great variable to the some variable here like this. 08:33.720 --> 08:36.090 All right, Don, let's turn it now. 08:36.990 --> 08:40.040 Cool, it still works and the result is correct. 08:41.510 --> 08:42.980 All right, that's all for now. 08:43.490 --> 08:45.230 See in the next picture, bye bye.