1 00:00:00,510 --> 00:00:01,410 Welcome back. 2 00:00:01,410 --> 00:00:07,230 In the last video we had a look at none pie's random number generator and how it's random but we can 3 00:00:07,230 --> 00:00:14,070 use no highs random seed method to make it not so random and create pseudo random numbers. 4 00:00:14,070 --> 00:00:22,060 Now we're going to have a look at different ways of viewing arrays and matrices. 5 00:00:22,160 --> 00:00:27,410 Here we go shift in into when we're making markdown cells so that our notebooks are beautifully formatted 6 00:00:28,160 --> 00:00:30,790 and actually before we jump into that. 7 00:00:30,920 --> 00:00:36,220 How do you think we'd find the unique numbers in these arrays. 8 00:00:36,290 --> 00:00:38,960 Maybe this one is a bit better because that's got integers. 9 00:00:38,960 --> 00:00:41,630 These are all floats here and they're way too long. 10 00:00:41,660 --> 00:00:48,010 But how would we find the unique numbers in random array for let's have a practice of how we might do 11 00:00:48,010 --> 00:00:48,800 that. 12 00:00:48,800 --> 00:00:53,930 So we'll open up a tab and we'll go how to find unique elements in an umpire. 13 00:00:54,250 --> 00:01:01,920 Beautiful that's pretty filled it's going gonna take us to the documentation known pi dot unique find 14 00:01:01,920 --> 00:01:05,600 the unique elements of an array wonderful that's what we're after. 15 00:01:05,730 --> 00:01:11,430 So if we go down in the documentation you'll see down the bottom there's examples. 16 00:01:11,430 --> 00:01:12,910 Now this is what we're after. 17 00:01:12,930 --> 00:01:18,390 This is the process you can go through say someone came to us and was like Hey you've got your random 18 00:01:18,390 --> 00:01:19,480 array for. 19 00:01:19,590 --> 00:01:21,450 I need the unique numbers from that. 20 00:01:21,450 --> 00:01:28,110 So we find the documentation we'd come to the examples section or we just read it to see if it does 21 00:01:28,110 --> 00:01:29,070 what we need. 22 00:01:29,290 --> 00:01:31,400 Then we'd have a look down here. 23 00:01:31,440 --> 00:01:36,180 So they've got an array a MP unique a array. 24 00:01:36,210 --> 00:01:38,250 It shows a unique numbers there. 25 00:01:38,250 --> 00:01:39,150 Well let's have a look. 26 00:01:39,150 --> 00:01:49,300 Let's practice MPD unique and remember we hit shift and TAB we've got information here find the unique 27 00:01:49,390 --> 00:01:50,740 elements of an array. 28 00:01:50,830 --> 00:01:52,570 Wonderful that's what we're after. 29 00:01:52,570 --> 00:01:59,020 So we're going to pass it random array for random array for shift and enter. 30 00:01:59,120 --> 00:02:04,270 And what this has given us is 0 1 3 4 5 6 8 9. 31 00:02:04,640 --> 00:02:12,530 If we come up here and that is because we created random array for using Rand int past at 10 so that 32 00:02:12,530 --> 00:02:17,260 means it will use the numbers between 0 and 9 of size 5 and 3. 33 00:02:17,360 --> 00:02:23,660 So we can see the uniques we haven't quite got all the numbers between 0 and 9 we're missing 2 0 missing 34 00:02:23,660 --> 00:02:31,420 7 beautiful but that's just a quick little tidbit of how you might find a function using num pi you 35 00:02:31,430 --> 00:02:36,230 might come across the documentation stack overflow is another resource that you will often come across 36 00:02:36,410 --> 00:02:37,790 but that's the steps you take. 37 00:02:37,790 --> 00:02:42,080 Now let's get into a section three viewing arrays and matrices. 38 00:02:42,080 --> 00:02:51,470 So we've got our arrays a one a two we created these earlier a three Now viewing arrays and matrices 39 00:02:51,770 --> 00:02:57,020 takes a bit of practice and created them of course to but if what you're seeing in this section had 40 00:02:57,020 --> 00:02:58,960 a view them is a little bit confusing a start. 41 00:02:58,970 --> 00:03:01,100 Don't worry I still get confused. 42 00:03:01,130 --> 00:03:03,900 The important point is to start practicing. 43 00:03:04,010 --> 00:03:09,570 So if we wanted to see element zero in a one we could use zero indexing. 44 00:03:09,740 --> 00:03:12,070 So let's try that beautiful. 45 00:03:12,110 --> 00:03:15,500 Let's go the same for A2 wonderful. 46 00:03:15,500 --> 00:03:19,700 Now this is gonna give us this first row here. 47 00:03:19,960 --> 00:03:21,340 Why is that. 48 00:03:21,340 --> 00:03:24,830 Well if we go above here a two dots shape. 49 00:03:25,300 --> 00:03:26,980 Okay so it's got two rows. 50 00:03:26,980 --> 00:03:28,120 So that makes sense. 51 00:03:28,150 --> 00:03:31,150 We're indexing into the first element of the shape. 52 00:03:31,150 --> 00:03:34,500 Now let's try a three a 3-D art shape. 53 00:03:34,810 --> 00:03:36,490 This is two three three. 54 00:03:36,520 --> 00:03:40,150 Let's get a 3 0. 55 00:03:40,190 --> 00:03:40,910 Wonderful. 56 00:03:41,030 --> 00:03:47,520 But if we have a look at all of A3 so it's giving us back the first row. 57 00:03:47,570 --> 00:03:59,040 So if we see here two three three in a three 0 is giving us back this first matrix or first array I 58 00:03:59,050 --> 00:04:07,180 remember the anatomy of our arrays and matrices although this is still an umpire Ray it can be referred 59 00:04:07,180 --> 00:04:08,790 to as a matrix. 60 00:04:08,850 --> 00:04:11,650 This is where some of the terminology gets a bit confusing. 61 00:04:11,650 --> 00:04:18,430 Usually a one dimensional array is referred to as a vector but anything more than one dimensional is 62 00:04:18,430 --> 00:04:24,160 referred to as a matrix but is also of type array. 63 00:04:24,310 --> 00:04:30,730 So that's the important thing to take away is that the array is still this but anything with more than 64 00:04:30,730 --> 00:04:35,740 one dimension is a matrix let's have a look at some more indexing. 65 00:04:35,750 --> 00:04:36,660 So we have a two. 66 00:04:36,660 --> 00:04:38,400 Maybe if we wanted index one. 67 00:04:38,420 --> 00:04:44,690 So we'll have a look at our Reagan index 1 what will this give us do you think shift and enter. 68 00:04:44,830 --> 00:04:47,860 So it's given us position 1. 69 00:04:48,070 --> 00:04:49,400 So let's try again. 70 00:04:49,420 --> 00:04:54,160 Let's do a bit more of a complicated one we can use slicing with arrays 2 which is beautiful just like 71 00:04:54,160 --> 00:04:59,060 Python less maybe we want the first two values of a three. 72 00:04:59,950 --> 00:05:08,430 So we want the first two values of each row column and array. 73 00:05:08,470 --> 00:05:13,170 Let's try that first two values of each shape. 74 00:05:13,250 --> 00:05:16,610 What do you think this will give so let's have a look. 75 00:05:16,700 --> 00:05:18,110 So we've got the first two. 76 00:05:18,410 --> 00:05:24,830 And the second two which is one two four five sets this section and then we've got the final two which 77 00:05:24,830 --> 00:05:27,850 is 10 11 13 14. 78 00:05:28,490 --> 00:05:29,450 Beautiful. 79 00:05:29,450 --> 00:05:35,150 Now remember doing this kind of indexing depending on how many dimensions your arrays have will take 80 00:05:35,150 --> 00:05:36,250 some practicing here. 81 00:05:37,070 --> 00:05:40,970 So best to just experiment create some arrays and start playing around. 82 00:05:40,970 --> 00:05:43,480 What if we did something like this. 83 00:05:43,580 --> 00:05:47,070 You'd get an error because there's too many indices. 84 00:05:47,120 --> 00:05:51,830 The reason why we can only do three is because of a 3D shape. 85 00:05:51,830 --> 00:05:53,370 There we go two three three. 86 00:05:53,690 --> 00:05:59,280 Let's try one more we'll create a four equals random dot Rand on it. 87 00:05:59,300 --> 00:06:06,140 We need an umpire at the front here random dot Rand end would do 10 and this time or make it a four 88 00:06:06,140 --> 00:06:09,090 dimensional array two three four five. 89 00:06:09,260 --> 00:06:12,980 We want to see it shift in into size is not defined OK. 90 00:06:13,010 --> 00:06:14,990 We keep forgetting to push equals here. 91 00:06:14,990 --> 00:06:15,440 That's right. 92 00:06:15,440 --> 00:06:18,120 You'll make some errors too when you're learning to code here. 93 00:06:18,140 --> 00:06:18,870 Okay. 94 00:06:19,070 --> 00:06:21,320 So a four we've got a fair few numbers here. 95 00:06:21,360 --> 00:06:22,880 We can scroll right down. 96 00:06:22,880 --> 00:06:31,880 So if we did a forward shape and then a 4 a.m. the shape is 2 3 4 5 we kind of knew that. 97 00:06:31,920 --> 00:06:34,200 So two by three by four by five. 98 00:06:34,200 --> 00:06:34,880 Yep. 99 00:06:35,010 --> 00:06:40,320 And the dimensions is four so this is a four dimensional array remember and dimensions can go up to 100 00:06:40,320 --> 00:06:42,730 any number you can imagine. 101 00:06:42,740 --> 00:06:51,020 So how would we get only the first four numbers of this vector here. 102 00:06:51,910 --> 00:06:59,460 Let's have a look at this size so none pi displays arrays from the outside integer inwards. 103 00:06:59,560 --> 00:07:00,850 So let's have a look at this. 104 00:07:00,870 --> 00:07:04,840 It's might be a bit hard to understand but with some practice you'll start to see. 105 00:07:04,840 --> 00:07:06,920 So we've got five here. 106 00:07:06,940 --> 00:07:13,330 So the furthest element on the right the furthest of the shape gets displayed on the innermost section. 107 00:07:13,450 --> 00:07:14,430 So five. 108 00:07:14,440 --> 00:07:15,970 There's five numbers here. 109 00:07:16,150 --> 00:07:21,010 And then for the next section is this section here. 110 00:07:21,010 --> 00:07:23,550 So there's one two three four. 111 00:07:23,560 --> 00:07:24,450 Yeah. 112 00:07:24,580 --> 00:07:26,170 And then three. 113 00:07:26,170 --> 00:07:27,820 So there should be three. 114 00:07:27,820 --> 00:07:30,080 One two three. 115 00:07:30,160 --> 00:07:30,390 Yeah. 116 00:07:30,430 --> 00:07:32,310 So one two three. 117 00:07:32,590 --> 00:07:33,970 And then two. 118 00:07:33,970 --> 00:07:36,010 So there should be two in the largest. 119 00:07:36,010 --> 00:07:37,870 So the outermost brackets. 120 00:07:37,990 --> 00:07:41,050 So this this is three and this is three here. 121 00:07:41,050 --> 00:07:42,670 So there's two there. 122 00:07:42,670 --> 00:07:46,510 Remember visualizing these is very hard to understand when you first begin. 123 00:07:46,510 --> 00:07:52,540 So if you're having some trouble try to create some random arrays with different shapes and then start 124 00:07:52,540 --> 00:08:01,170 to count backwards from the outermost number on the inner most displayed array but let's say how would 125 00:08:01,170 --> 00:08:14,170 we get the first four numbers of that in a most array so that's the innermost here number five. 126 00:08:14,180 --> 00:08:23,570 So what we could do is slice these first three dimensions and then slice this one we only want the first 127 00:08:23,570 --> 00:08:24,510 four. 128 00:08:24,680 --> 00:08:35,750 So let's try that a four slice all of dimension 1 slice all of dimension to all of dimension 3 but only 129 00:08:35,750 --> 00:08:41,380 up to the first four numbers of dimension 4 shift into wonderful. 130 00:08:42,130 --> 00:08:47,480 So that only gives us the first four numbers of the innermost dimension. 131 00:08:47,770 --> 00:08:57,260 And if we got rid of packed of three that two there we go we can start to see how we can really slice 132 00:08:57,260 --> 00:09:03,130 and dice our arrays and and matrices to give us back any kind of numbers that we might want to see. 133 00:09:03,130 --> 00:09:04,050 All right. 134 00:09:04,130 --> 00:09:06,680 Now we've seen a few different ways to create arrays. 135 00:09:06,680 --> 00:09:10,170 We've seen a few different ways to index them and view them. 136 00:09:10,170 --> 00:09:13,950 And I'm using the term array and Matrix independently. 137 00:09:14,060 --> 00:09:16,570 You can use them independently yourself. 138 00:09:16,730 --> 00:09:22,400 What we're going to do next is figure out how to manipulate and compare different arrays which is the 139 00:09:22,400 --> 00:09:26,060 crux of what machine learning does to find patterns in numbers. 140 00:09:26,060 --> 00:09:28,550 So have some practice taking a little break. 141 00:09:28,580 --> 00:09:34,100 Try out a bit of slicing create your own array and see different ways of viewing it and I'll see you 142 00:09:34,100 --> 00:09:34,930 in the next video.