1 00:00:00,410 --> 00:00:04,680 All right now we've had a little bit of a conceptual overview of num pie. 2 00:00:04,710 --> 00:00:08,130 Let's get hands on and start to write some num pi code. 3 00:00:08,890 --> 00:00:13,620 So I'm going to follow the little workflow that we've we've kind of set up over the past few lessons 4 00:00:13,620 --> 00:00:16,790 and sections start off in a terminal. 5 00:00:16,910 --> 00:00:21,620 And I'm going to change directory into this little folder that I've got on my desktop. 6 00:00:21,620 --> 00:00:26,290 Yours may be stored somewhere else to see the slash airmail course. 7 00:00:26,390 --> 00:00:30,650 Now I've got a folder in here called sample project which has my environment. 8 00:00:30,650 --> 00:00:34,480 You'll want to change into the same folder that contains your environment. 9 00:00:35,390 --> 00:00:36,210 Hit enter. 10 00:00:36,220 --> 00:00:38,130 Now nowhere in the sample project folder. 11 00:00:38,150 --> 00:00:39,110 Beautiful. 12 00:00:39,660 --> 00:00:46,580 And we're going to check using Condit end list where our environments are so I can say I've got one 13 00:00:46,580 --> 00:00:48,170 here I've got a few currently. 14 00:00:48,420 --> 00:00:54,170 Base is activated because got the star but I want this one because that's in my sample project folder 15 00:00:54,510 --> 00:00:55,630 so I'm going to type it out. 16 00:00:55,640 --> 00:01:01,340 You could copy this and do Conda activate this here but where in the practice of writing things for 17 00:01:01,340 --> 00:01:09,140 ourselves because I want to get as used to as possible writing as much code as possible email cause 18 00:01:10,340 --> 00:01:11,560 sample project. 19 00:01:11,560 --> 00:01:17,020 Now remember you'll want to change yours to wherever your environment folder is stored activate the 20 00:01:17,020 --> 00:01:23,680 first thing we notice is that this has changed from base to our active environment now and next step 21 00:01:23,770 --> 00:01:31,010 is to create a Jupiter notebook our favorite workspace tool let's load that up now listen open our browser 22 00:01:32,090 --> 00:01:37,040 we brought to the Jupiter dashboard it's nice and zoomed in excellent we've got our folders here and 23 00:01:37,040 --> 00:01:40,030 files that are within our sample project folder. 24 00:01:40,070 --> 00:01:45,140 Yours may be a little bit different but we can see in my case about the introduction to Panda's notebook 25 00:01:45,170 --> 00:01:50,300 the example notebook from before my environment folder we're not worried about these we're going to 26 00:01:50,600 --> 00:01:58,250 start a new notebook Python 3 first thing we're gonna do is rename it to introduction to num PI because 27 00:01:58,250 --> 00:01:59,630 that's what we're working on. 28 00:01:59,780 --> 00:02:06,020 Hit enter and we'll save that when we come back to the dashboard we've now got introduction to num pi 29 00:02:06,140 --> 00:02:08,020 running beautiful. 30 00:02:08,390 --> 00:02:17,660 Now the first step for using num pi is to import it import num pi as an P MP is just short for num pi 31 00:02:18,050 --> 00:02:24,170 if you see this abbreviation somewhere you can probably safely assume that it's referring to num pi 32 00:02:24,290 --> 00:02:30,080 it's just to prevent us from having to type out num pi every single time we want to use a command we'll 33 00:02:30,110 --> 00:02:36,050 hit shift and enter beautiful now in this section and we're going to be focused on num PIs data type 34 00:02:36,350 --> 00:02:42,050 and attributes so that's all we'll create a little heading because we are in the business of making 35 00:02:42,050 --> 00:02:49,160 attractive and communicate of notebooks data types and attributes will escape and M to turn it into 36 00:02:49,160 --> 00:02:53,380 a markdown cell wonderful data types and attributes. 37 00:02:53,390 --> 00:03:06,030 Now data types as a plural is kind of a lie because none pi main data type is indeed array it's only 38 00:03:06,030 --> 00:03:12,720 really got one day at a time so everything you see in num pi is likely an NDA array and this stands 39 00:03:12,720 --> 00:03:20,940 for n dimensional array and an array can be almost any list of numbers you can imagine an n dimensions 40 00:03:20,940 --> 00:03:25,770 means or the list of numbers could be almost any shape that you can imagine but rather than talk about 41 00:03:25,770 --> 00:03:33,690 it let's create it so A1 for array one will create a sample array now you can do that by going num pi 42 00:03:33,840 --> 00:03:42,120 dot array which just means access the array function from num Pi which we've imported as MP and to build 43 00:03:42,120 --> 00:03:48,510 an array which is a list of numbers we want to pass at a list of numbers so let's do that and then to 44 00:03:48,510 --> 00:03:53,140 see it we'll type it again shift and enter Excellent. 45 00:03:53,190 --> 00:03:56,700 We've got our first name pie right now this is exciting. 46 00:03:56,700 --> 00:04:01,870 Let's check the top of it nun pie DOT and the array. 47 00:04:01,950 --> 00:04:02,520 Wonderful. 48 00:04:02,520 --> 00:04:04,110 So that's the same as here. 49 00:04:04,170 --> 00:04:07,000 Remember this is just n dimensional array. 50 00:04:07,140 --> 00:04:14,010 Now for some more examples let's create a few more arrays empty array or type out this one. 51 00:04:14,100 --> 00:04:16,240 This will have two brackets. 52 00:04:16,290 --> 00:04:18,390 We'll see why in a second. 53 00:04:18,390 --> 00:04:19,580 Now we'll separate it. 54 00:04:19,740 --> 00:04:20,760 We'll go to another line. 55 00:04:20,760 --> 00:04:23,890 One two three four five actually. 56 00:04:24,030 --> 00:04:26,070 Let's make this six point five. 57 00:04:26,070 --> 00:04:28,150 And this three point three. 58 00:04:28,200 --> 00:04:32,690 So we've got some floats as well as integers inside num pi. 59 00:04:32,700 --> 00:04:39,540 There we go we might make another one called a three empty array and this one we might actually do three 60 00:04:39,540 --> 00:04:40,440 brackets. 61 00:04:40,440 --> 00:04:42,950 So we're getting a bit adventurous here. 62 00:04:43,050 --> 00:04:45,370 We'll make this one two three. 63 00:04:45,390 --> 00:04:47,410 Let's go all the way up to 18. 64 00:04:47,490 --> 00:04:50,640 Bear with me type along if you can. 65 00:04:50,700 --> 00:04:56,110 Five six and then we'll go seven eight. 66 00:04:56,130 --> 00:04:57,880 Want to make sure it looks all right. 67 00:04:57,910 --> 00:05:00,790 Nine and then leave two brackets here. 68 00:05:00,810 --> 00:05:01,740 Oh actually yeah. 69 00:05:01,740 --> 00:05:02,520 Two brackets. 70 00:05:02,520 --> 00:05:03,960 That's correct. 71 00:05:03,960 --> 00:05:10,980 I'm just counting the number of brackets you'll see why this is important in a moment which is typing 72 00:05:10,980 --> 00:05:18,990 out the numbers from one to 18 in a very kind of cryptic format at the moment 13 14 15. 73 00:05:19,060 --> 00:05:22,980 Got a little bit more 16 17 18. 74 00:05:22,980 --> 00:05:26,370 My goodness we made it in the end. 75 00:05:26,370 --> 00:05:27,640 Let's see if this cell runs. 76 00:05:27,660 --> 00:05:28,330 Beautiful. 77 00:05:28,350 --> 00:05:32,250 If in doubt run the code now why would we do that. 78 00:05:32,250 --> 00:05:33,920 Well let's have a look at these two arrays. 79 00:05:33,990 --> 00:05:39,200 A two there we go we can see that we've got two sets of brackets here. 80 00:05:39,290 --> 00:05:40,820 You got two more here. 81 00:05:40,840 --> 00:05:44,200 Now let's have a look at a three. 82 00:05:44,620 --> 00:05:45,190 OK. 83 00:05:45,250 --> 00:05:49,810 Now this one it's kind of come out the exact same way as we've got here. 84 00:05:49,810 --> 00:05:50,630 Mm hmm. 85 00:05:50,650 --> 00:05:55,960 Now before we get any further and check out some of the attributes that these arrays have built in let's 86 00:05:55,960 --> 00:05:58,930 have a look at the anatomy of an array. 87 00:05:58,960 --> 00:06:01,590 So this is the anatomy of a name pi array. 88 00:06:01,600 --> 00:06:04,040 This is a one the one that we've just created. 89 00:06:04,060 --> 00:06:05,240 This is a two. 90 00:06:05,350 --> 00:06:09,410 And this is a three as a reason why I put in these numbers here. 91 00:06:09,430 --> 00:06:13,470 So we can exemplify the kinds of shapes of different arrays. 92 00:06:13,470 --> 00:06:18,340 Now this is very important in machine learning because oftentimes with a machine learning algorithm 93 00:06:18,370 --> 00:06:25,300 your main focus will be making sure the shape of your data that goes into a machine learning algorithm 94 00:06:25,600 --> 00:06:29,940 lines up with the other data that you're putting in as well as the output. 95 00:06:30,140 --> 00:06:32,230 But we'll see that in future sections. 96 00:06:32,230 --> 00:06:35,780 This is just learning the shape of different num pi arrays. 97 00:06:35,830 --> 00:06:37,350 So I've got one here. 98 00:06:37,420 --> 00:06:39,720 There's one row and three columns. 99 00:06:40,150 --> 00:06:43,030 So this would be shape 1 3. 100 00:06:43,030 --> 00:06:50,400 Now this kind of data here is referred to as an array or vector a vector is just a one dimensional array. 101 00:06:50,790 --> 00:06:56,230 If we go to this next one which is A2 we've got two rows and three columns. 102 00:06:56,230 --> 00:07:03,070 So this one has the shape to three it's more than one dimension and can be referred to as a matrix. 103 00:07:03,100 --> 00:07:07,370 So if you hear something referred to as a matrix it's probably got more than one dimension. 104 00:07:07,380 --> 00:07:09,330 So see how a vector vectors just one row. 105 00:07:09,370 --> 00:07:11,530 This matrix has two rows. 106 00:07:11,530 --> 00:07:17,020 And if we go down to a three we're starting to get three dimensional here because we've got got the 107 00:07:17,020 --> 00:07:18,640 access going back here. 108 00:07:18,700 --> 00:07:22,570 This is where the N N N dimensional array comes from. 109 00:07:22,570 --> 00:07:28,210 That's very hard for us humans to visualize anything more than three dimensions. 110 00:07:28,210 --> 00:07:33,280 But in num pi and with computers you could have as many ends as you want. 111 00:07:33,280 --> 00:07:38,590 So this could go up to four to five up to six up to seven depending on what type of data are working 112 00:07:38,590 --> 00:07:39,040 with. 113 00:07:39,040 --> 00:07:45,720 You may have thousands of different dimensions but if you hear axis zero it's usually referring to rows. 114 00:07:45,790 --> 00:07:52,960 Axis one is usually referring to columns and then access n is usually referring to dimensions that are 115 00:07:52,960 --> 00:07:54,970 beyond just rows and columns. 116 00:07:55,600 --> 00:08:04,030 So this array here or A3 would have the shape to three three because there's two rows three columns 117 00:08:04,410 --> 00:08:06,430 and we've got three across here. 118 00:08:06,430 --> 00:08:07,790 So that's the final one here. 119 00:08:07,810 --> 00:08:13,280 And now if n was higher there might be more commas and this little shape would extend out here. 120 00:08:13,840 --> 00:08:14,500 Okay. 121 00:08:14,740 --> 00:08:18,380 So now we've got the anatomy of a no higher rate down pat. 122 00:08:18,430 --> 00:08:21,360 Don't worry you can take a screenshot of this if you like. 123 00:08:21,370 --> 00:08:24,100 Otherwise it'll be in the resources section. 124 00:08:24,160 --> 00:08:29,170 Let's have a look at some of the attributes associated with no higher res. 125 00:08:29,170 --> 00:08:38,460 So the first one we'll take a look at is a one dot shape so it's three comma something. 126 00:08:38,460 --> 00:08:39,900 Now this is blank. 127 00:08:40,050 --> 00:08:48,900 Now the way num pi kind of format this data is that although we've said that the shape is 1 3 num pi 128 00:08:48,930 --> 00:08:52,080 kind of stores it without the row at all. 129 00:08:52,080 --> 00:08:54,900 So it's just got the three numbers here. 130 00:08:54,900 --> 00:08:58,140 That's just a little tidbit of how num pi displays some kind of shapes. 131 00:08:58,140 --> 00:09:04,140 But if we have a look at the shape of A2 we can see that it's the same as what we've used in our anatomy 132 00:09:04,140 --> 00:09:05,610 of a known pi array. 133 00:09:05,680 --> 00:09:12,740 Then if we go the same for a 3 2 3 3 OK let's have a look at a few more. 134 00:09:12,800 --> 00:09:20,300 So if we are a one and dim which is short for number of dimensions maybe we do a two dot end them and 135 00:09:20,360 --> 00:09:21,860 a three them. 136 00:09:22,370 --> 00:09:29,900 And what putting the comma here will do is when the code comes out it'll just print it with commas spacing 137 00:09:29,900 --> 00:09:31,890 that three different variables apart. 138 00:09:31,910 --> 00:09:33,800 So this is number of dimensions. 139 00:09:33,800 --> 00:09:36,690 So A1 let's have a look at it again. 140 00:09:36,860 --> 00:09:39,190 One has a dimension of 1. 141 00:09:39,320 --> 00:09:49,660 We'll have a look at A2 as a dimension of 2 and A3 has three dimensions. 142 00:09:49,710 --> 00:09:55,870 And so this is where the MDMA data type comes in is that these dimensions depending on how complex your 143 00:09:55,870 --> 00:09:58,330 data is could just keep going. 144 00:09:58,360 --> 00:10:02,710 And now the whole premise here is we'll see some practical examples in the next couple of videos is 145 00:10:02,710 --> 00:10:09,010 that whatever data you're working with it somehow gets turned into numbers and then a machine learning 146 00:10:09,010 --> 00:10:12,250 algorithm will find patterns in these numbers. 147 00:10:12,250 --> 00:10:17,110 Now depending on what data you're working with will depend on how many dimensions Zehra. 148 00:10:17,270 --> 00:10:18,390 But let's not stop there. 149 00:10:18,400 --> 00:10:21,270 Let's have a look at the D type attribute. 150 00:10:21,310 --> 00:10:23,990 You might be able to guess what data type these are. 151 00:10:24,040 --> 00:10:33,300 Let's go here shift into so we can see in our A1 array we've got ints in our A2 we've got floats as 152 00:10:33,300 --> 00:10:34,120 well as int. 153 00:10:34,170 --> 00:10:39,690 But it's going to default to float because that can only be one kind of data type so it will automatically 154 00:10:39,690 --> 00:10:48,230 just turn the rest of the numbers in here into floats and A3 is also just integers we've got a couple 155 00:10:48,230 --> 00:10:48,580 more. 156 00:10:48,650 --> 00:10:59,570 A one size a two size a three size we've got three elements in a one we've got six elements in a two 157 00:10:59,600 --> 00:11:02,870 and we've got 18 elements in a three. 158 00:11:03,080 --> 00:11:10,730 If we have a look at a three that makes sense beautiful so the size attribute tells us how many elements 159 00:11:10,730 --> 00:11:13,800 we've got total in our right now. 160 00:11:13,970 --> 00:11:20,680 One last one which is type 2 type 2 type a 3. 161 00:11:20,900 --> 00:11:24,470 I think we've already seen this but I'm going to get you to guess what it is before we hit shift and 162 00:11:24,550 --> 00:11:29,850 into 3 2 1 these are all in the array. 163 00:11:29,860 --> 00:11:38,140 So although they vary in size and shape a A1 a two and a three are all of the type NDA right now this 164 00:11:38,140 --> 00:11:40,640 is an important concept to remember. 165 00:11:41,080 --> 00:11:47,980 No matter what type or what shape your number higher rate is all of the functions and different data 166 00:11:47,980 --> 00:11:50,920 manipulations that you see throughout this section. 167 00:11:50,920 --> 00:11:52,380 If it's in an umpire. 168 00:11:52,390 --> 00:11:58,900 If your data is in a m the array data type all of the things were about to go through can be used on 169 00:11:58,900 --> 00:11:59,670 that. 170 00:11:59,710 --> 00:12:06,520 So that's a very important point to remember is that the NDA Ray is a universal data type and it's very 171 00:12:06,580 --> 00:12:14,380 very flexible to now to really exemplify num pi being the backbone of other scientific data packages 172 00:12:14,380 --> 00:12:16,050 that is let's put a note here. 173 00:12:16,060 --> 00:12:22,250 Create a data frame from num pi array. 174 00:12:22,890 --> 00:12:29,410 So let's have a look first will import panders as PD beautiful and then we might create one from our 175 00:12:29,410 --> 00:12:30,880 existing array. 176 00:12:30,970 --> 00:12:35,890 So the data frame we're just gonna pass at A2. 177 00:12:35,960 --> 00:12:41,130 Let's have a quick look at what A2 is a A2 wonderful. 178 00:12:41,190 --> 00:12:42,390 So there's A2. 179 00:12:42,420 --> 00:12:43,940 Now let's see what that looks like. 180 00:12:44,010 --> 00:12:47,100 You need to view it shift and enter. 181 00:12:47,100 --> 00:12:48,300 There we go. 182 00:12:48,300 --> 00:12:52,470 So this is a panda's data frame and this is our num pi array. 183 00:12:52,470 --> 00:12:58,500 So essentially no matter what's in our Panda's data frame if it's all numbers and panders is built on 184 00:12:58,500 --> 00:13:06,930 top of num pie so to represent our data as a data frame it's just combining num higher res in a formatted 185 00:13:06,930 --> 00:13:08,070 way. 186 00:13:08,070 --> 00:13:13,020 So that's a very important point to remember as well is that once we start to get into the weeds of 187 00:13:13,020 --> 00:13:18,810 num pie and start to work out what kind of numerical computing it can do we can start to think okay. 188 00:13:18,930 --> 00:13:24,840 So if we have some data and we imported and panders it's actually just a different combination. 189 00:13:24,860 --> 00:13:30,900 Umpire res so if we want to perform some manipulations on it we're actually just performing manipulations 190 00:13:30,900 --> 00:13:37,380 on different lists of numbers horror as a brief introduction to num plays main data type. 191 00:13:37,380 --> 00:13:43,260 That's the main thing to take away from this is that NDA array whatever array you have in num pi is 192 00:13:43,260 --> 00:13:49,170 of type in the array and that panders and other machine learning algorithm packages are built on top 193 00:13:49,170 --> 00:13:55,130 of num pie and machine learning is finding patterns in num pi arrays. 194 00:13:55,170 --> 00:14:00,480 So with that being said let's take a little break if you need to go back and explore create an array 195 00:14:00,480 --> 00:14:02,360 of your own by trialling it out. 196 00:14:02,580 --> 00:14:05,250 If in doubt run the code and I'll see in the next video.