Solving 100 Python NumPy Problems! (From easy to difficult)

Solving 100 Python NumPy Problems! (From easy to difficult)

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI

Оглавление (45 сегментов)

Segment 1 (00:00 - 05:00)

hey what's up everyone and welcome back to another video so today we will be walking through 100 numpy exercises so we did this previously with pandas but uh decided let's run it back with a bunch more problems this time with the numpy library so we're going to be working off of this repo um scene right here I'll also make sure to link it in the description and the way that I recommend watching this video is that there are a lot of exercises and I recommend trying a lot of these exercises on your own pausing the video and then when you want to see how I would approach the problem resume the video and see my solution I'll make sure to Tim stamp everything so that you can find exactly the problem that you're working on down uh in the YouTube description but I think let's just uh get right into it g to be going to be a blast um so I'm going to go ahead and Fork this repo and then I will copy this link I will open up a terminal window I will go into my code folder and I'll go ahead and do a get clone and paste in that link and now I can navigate into that repo and I'll do a code to open up that so that's a vs code um function and then that opens up automatically the repo so you should be able to read now what's on the screen again links are in description I don't need to see the October 2024 release of Visual Studio code let's um go to maybe the readme to start maybe not the readme uh Okay cool so there's some hints and stuff here all right cool so let's start with this 100 numpy exercises. ipynb file I'm also if you're working with Visual Studio code I'm going to do a command shift p I'm going to select interpreter and then I have one I just call YouTube I'll install on my package is there you don't need to have a virtual environment but it's just kind of a good practice um then I guess I'll try running initialize up p and see if that works use YouTube cool okay so I might need to install some packages to do that I can go ahead and open up a terminal window and we can see that I'm on my YouTube kernel or YouTube virtual environment I will start by doing install actually there's a requirement St txt file here so uh good practice with anything here it doesn't look like it has the library that I'm looking for but we'll see if this works I'll do a pip three install dasr requirements. txt I think I honestly don't think that we necessarily need these specific ones and it might have issues with um these versions so I'm going to go ahead and do a pip 3 install numpy tip three install pandas tip three install Jupiter pip 3 install Jupiter themes I really don't know if we need all these libraries pip 3 install MD utils okay everything installed successfully we might just have some sort of python incompatibility issue go back to 100 npy exercises let's see if we can run this initialize now looks like it worked and now let's go ahead and start doing some problems all right problem One Import the numpy package under the name NP and I think one thing I will mention is that I recommend trying to do these problems without co-pilot completions because I feel like if I turned this on it probably would automatically autocomplete a lot of these so like we that I'll see if it would autocomplete multiple yeah maybe it doesn't know to do that but I just think that I'm going to not use copil chat but I

Segment 2 (05:00 - 10:00)

will keep the like completions and stuff on you do want to be able to see the numpy uh like what we have access to so if I type in NP here it is nice to see these autocompletes so I'm going to leave those on and this is just something you remember you get some like private type methods if you do underscore and with Mo most packages you can do um np. version however I don't know what it means exactly by the config is there also a np. config or something that I can what do I have access to here like maybe dick I don't know if that's what it's looking for so I'm going to do a hint real quick on uh on this configuration one okay I mean just basically gave me the answer but okay np. show config I guess I probably could do a function call okay so if you need the config you can do it this way I'm not exctly sure where you would use the config but that is how you do it okay let's go null Vector of size 10 so I'm guessing there might be like a np. null trying to think mp. array or mp. n it's not a function a n Vector of size 10 I mean also maybe it's just wanting me to do like in your n Vector equals NP do but I mean like easiest thing is like you can start with an array um of like none and I suppose I could like multiply this by 10 but that's not like the most could do this repeat 10 to is that what it's looking for if we look at our n Vector I'm going to do a like is that what it's wanting I might have to do a hint here and actually let's just go back hint okay we also can do answer end so we can double check if our answers are correct might also just real quick look at the read me I wonder is there a nice that's actually kind of cool I'm using Corto to look at this in actual uh okay I'm going to just I didn't know if there was a way to automatically check things go back um I might need a hint here if this is correct or not hint three why is it not recognizing hint oh NP oh I that's confusing I you can do np. Zer and then just do like either I think probably just 10 would work let's see what happens there that would work that I feel like I thought I was talking about nuns though or like actual NES so that definitely makes zeros the sentence um you also could like shape this in different ways you could do like 10 comma 1 if you really wanted uh you know a certain shape or something but I think np0 is 10 seems right to me and I guess we can do what was it solution or answer n so we could do real quick run that and then we will type in answer three and p 0 is 10 okay cool we got that right all right moving right along how to find the memory size of any array well we could have take our null vector and see the memory impact of that I think starting with typing out the numpy unit that you're using makes sense and I think if we do like me or maybe there's let's see num p. m size

Segment 3 (10:00 - 15:00)

let's do um null vector. siiz is there a MIM size or size of it's that 192 bytes let's see I'm going to just check one more time no p. memory size of object in memory in bytes okay so this right here we did null Vector dot size of that would give us in byes the size um so that looks good to me I think to double check you could try like some smaller nump array so like we would expect if we made some sort of array called np. array and let's just say it's a one and we made this like an INT data type equals int 8 so that would mean uh eight bits is it not I got to do it with quotes there' be eight bits or one bite so this should be a much smaller array I'm going to real quick do a do size of just to kind of check to see if this seems like the right function you always could Google it too 113 uh probably makes sense I don't know what the standard size of like just the overhead of setting up a array is um that looks good to me I guess I can do a hint 4 real quick to see oh item size okay we'll see if um that gives us the same answer eight H this is interesting there's if you did item size types null vector let's look at the solution okay I'm curious what this will give us n Vector do size times n Vector do item size because I bet you this will give us the same exact answer as what we just had 80 ah okay this is the memory size specifically of the array itself but I guess the overhead of the numpy um like going back to what we just did with the a equals NP do array one and then we did uh data type equals int 8 like this array size is just 8 Bits one bite and so when we looked up the size of that and this is you know you're learning as you go by figuring out these built-ins we see it's 113 okay so the actual memory impact of this should just be one so I'm curious what will happen if we do size times a. item size you would get just one uh so it was one bite for all of this but the overhead for setting up a array is 112 I'm guessing bytes so we would expect that our total memory impact of null Vector would be 1 12 plus 80 which I think is 192 so I'm just curious again if we get that yeah look at that so 112 is the overhead of setting up the numpy array 80 is the actual memory size specifically of the array weird details but uh I think worth noting hopefully that kind of made sense but um I'll kind of leave it I don't know I'll leave both on the screen here

Segment 4 (15:00 - 20:00)

total memory and this is memory size of just the array hopefully that kind of makes sense how to get documentation of the numpy add function from the command line that's so interesting we have to do a command line type thing here num. add I think we can do D mp. add. doc I guess that's a doc string let's see I mean this gives us the docks it's not really via the command line though um I mean using we could do something similar all right so go to our terminal the equivalent would be python we want to activate our virtual environment we type in Python do import numpy as NP and then we do mp. add do Doc and then I guess print that I mean this is from the terminal so I don't know if this is what it's looking for or if it's looking for something else but I mean this is the documentation for it luckily that kind of just autop populates in our terminal so let's try a hint here guess we can't do the hint with having the print statement there it's kind of confusing np. info I mean I could also do let's see let's try to do it like that np. info and I think a key thing here is that there's multiple ways to do certain things and we could honestly do probably np. add and look that gives us the um documents as well so I'm curious what the answer is here multiple ways to do the same thing oh why did I do answer three answer five okay so from the command line you could do all of this in just one go uh they give this because that's what you need to do in your jupyter notebook but you also could actually do um an explanation point python - c um import numpy as NP np. info np. add this will also work so we see we get that so exclamation point can also run terminal commands in addition to what they provided which was this percent run so I'll leave that on the screen as well and you can also do what we did here all right create a null Vector of size 10 but the fifth value which is one I mean this is just repeat a similar process to what we did previously so we could do NES equals np. because that's apparently What It Wants size 10 and then the fifth value is one so now we need to just think about are we talking about the fifth index or the fifth value which is the fourth index so we start with zero is the first index so the fifth index is actually NES 4 equals 1 and then if we print it NES we will see that 1 2 3 4 Fifth Element is one the rest are zeros I'm pretty happy with this solution let's see if that is what they say array four yep and then I bet you if you see the answer um yep exactly just what we did we just had a different name guess nulles is maybe not the most descriptive name because we do actually add on one um but I'm happy with

Segment 5 (20:00 - 25:00)

this all right create a vector with values ranging from 10 to 49 this just uses a function that you should probably know um easiest way to do this you could obviously do like np. array um and pass in a list 10 11 12 13 14 uh that would be really frustrating though so the better way to do it would be do p. AR range um and I bet you if we look at the documentation for this um if you looked up the actual documentation for this um there's a start and a stop I guess you can keep scrolling down oh God mp. range I'm struggling here oh yeah return evenly space intervals within a given interval has a start value and a stop value and a step so this is just like when you do like a list comprehension or uh you know use the uh for I in range type function with normal python syntax so we could do 10 and then if we want it to go to 49 we actually need to do a to 50 because this number is exclusive and then our step is one but that's the default value so we could just leave this blank and we will call this like I don't know nums and if we print nums we will see that we get our Vector with range uh with numbers 10 to 49 um not including 50 reverse Vector um I mean there's multiple ways to do this there might be a reverse method but I think the easiest is actually to just use a list or like a slicing syntax just do colon which basically means you know all values and then negative one so we look at this we do see that it is reversed U this is the same as doing like 0 to 50 negative 1 oh maybe not necessarily because it's going actually from 50 to zero yeah that would be close to the same it's kind of confusing if you actually put in values here so my recommendation is if you just need all elements and you need it to go backwards colon negative one uh and I'll just call this reversed nums equals numes print reversed nums let's see what they have for a solution here hint 8 yeah same thing here and then if we actually look at the answer eight same thing cool oh no I deleted the whole Cale command Z I wanted to just delete this line create a 3X3 Matrix with values ranging from0 to 8 so this is very much similar to np. AR range this time we want to actually pass in a shape um is there a shape part here I mean there's two ways to do this you could just use num. AR range and then reshape it I don't know if I can do that just directly via the function so I'm going to use two functions here um we got mp. a range we'll pass in 0er to nine and then I'm just going to reshape we'll pass it in as 3x3 so this will work do see that curious if they have a different solution I just call this Matrix print Matrix yeah I'm curious if they use a different solution or if they just do this answer not yep they did the same thing and I guess I didn't need to do 0 to 9 if I just included uh n it would have known that it starts at zero naturally so guess one good thing to know about that find indices of nonzero elements from one to 0040 okay this is going to be a numpy do where so I'm going to call this uh like array equals np. array I'm just going to

Segment 6 (25:00 - 30:00)

pass in the values they give us 0 04 0 so we expect the indices to be the returned list to be um 0 one and then 2 3 4 0 one and four so to get that we can do a np. where or actually I guess I think we can just do array. wear oh no maybe not okay mp. wear and then we just want to do array and we want it to be non zero so not equal to zero and we could say indices equals np. whereare print indices 0 1 4 that's what we expected so that looks good just for the heck of it let's look at what they put here oh they did a nonzero so there's multiple ways to do this um nonzero is another function I didn't know that was a built-in np. wear is a little bit more uh I guess Universal of a function but this might be you know a bit optimized cool let's go to 11 3x3 identity Matrix um so an identity Matrix I believe it is it's been a little while since I've done uh linear algebra but I believe it this forget which way the uh believe it is this um one's on the diagonal um I'm guessing there's a built-in identity function I should maybe just double check what an identity Matrix is this is kind of embarrassing but it's been a little while since I've done a math class images okay cool I was correct I just didn't know if the diagonal was the other way so how do we do this in numpy well I can do like quote quote do a comment here quote quot quote so we know what we're working towards and I could do something like np. identity oh look at that there is an identity function and it just n which is going to be the I mean this is always in square matrices because it wouldn't make sense in other types of matrices cuz you know it's from one corner to the other corner so identity 3 is going to be our identity Matrix so I'll just call this I and honestly I guess like if I was naming this in a software project I would want to call it like identity Matrix or something like that print identity can't spell identity look at that looks good and let's just check what they did for their answer oh why do I type in three there answer 11 oh there's another one just called i e ye that's kind of confusing to me but cool to know same exact thing though I bet you they are uh completely identical I'm curious if it says anything about I here I don't know but another way to do it is np. I that's just confirm that works yeah autocomplete is definitely helpful because if you have a sense of what you think the function might be uh you usually can start typing something like that and you'll usually see an autocomplete option all right create a 3x3x3 array with random values to do uh random values in numpy you're going to want to do np. random and then this gives you access to all sorts of random functions so you have like randint random which is going to be 0 to one uh so it doesn't really matter what we do here I might just do np. random.

Segment 7 (30:00 - 35:00)

random and then we need to pass in the size which is going to be a tuple which is 3x 3 by 3 and I'll just call this randos equals mt. random. random and I'll print out randos we see that 3x3 another 3x3 and a final 3x3 so that's a 3x3x3 a threedimensional matrix here let's see what the solution says yeah they the same thing as us create a 10x10 array with random values np. random. random and we want it to be 10 by 10 and we want to find the minimum and maximum values maybe it makes sense for us to do like randant here it doesn't change anything actually this would does change something because it's a different type of function um if we did Rand int we would first need to pass in a low value and a high value and then pass in the size so if you see that the nice thing about this though is that uh Rand ins is that we know that the max should be around 50 and we know that um the Min should be around zero I think you can probably also seed this there might be some way to seed this what a seed is in random values is like it sets the randomness kind of in stone so even though you're getting these random arrays and whatnot every time you repeat running the code it stays the same so it's good if you need reproducibility in something you're running but like if you needed that actual Randomness in the wild you'd want to remove the seed so I think if I did something like np. random. seed and I set it to like 42 when I generate this array it's going to always be the same array so let's now look at randant you see how I keep running this keeps having the six at the bottom and the 38 in the left if I instead changed removed the line now it completely Is Random so that's what a seed does if you need like reproducibility in like a test environment uh and if we want to find the Min and Max we can just do Max we get 49 and if I wanted the Min just do Min any we get zero so that makes sense I mean this is going to change because we don't have a seed there but this is what we need to do cool let's go to 14 um credit ROM Vector of size 30 and find the mean value so call this array 30 equal np. random and if we want to get the mean value we can just do array 30. mean and we expect it to be around 0. 5 always because this is between zero and one generating Grom values so and we see that when we run this it is around that 0. 5 with some you know expected fluctuations one thing that's cool I guess it wouldn't be that useful in this case but you can change the axis of this so if I said axis equals 1 I said axis 0 uh I guess it doesn't necessarily work in this I did a reshape to 10 by3 and then I ran different axes uh if we print out and we'll probably see this in future problems but basically then this could do the average just on columns or just on rows if we do one um so this is the average just on the rows here um but we don't need to actually do that we'll just use axis equals none and just get the single value or you could just that's the default value so you could also just do this cool 15 we're cruising right

Segment 8 (35:00 - 40:00)

along curious what the answer is here for 14 yeah exact same thing 15 create a 2d array with one on the border and zero inside that's interesting so it's looking for something like R this with quots again for one zero one one looking for something like this I mean to make this Universal uh let's think I mean like the simplest thing that I would do is just do like NP you know like ones equals np. On's 3x3 and then I would know that the we print out ones uh we know that this is the zeroth row this is the first row we're talking about indexing and then this is the first position so I could do something like ones one comma one is it like this equals zero then print ones it might be uh okay so this gives me first row and then First Comm in that and I'm talking about first as an index one so that's one way to do it I'm trying to think if you wanted to be more generic you could make like a zero Matrix you want to be more generic you do something like zeros and this has to be like odd sized I mean I guess it depends on if it's even or like what I'm just saying is if this was just a 2 by two it doesn't make sense in this case so we do need like uh one dimension to at least be odd equals three let's say size and then you could do zeros equals like uh np. Zer 2 size minus two you do some weird stuff here where then you have ones from we got an index on both positions here so ones from one to the length or like this is not perfect that would give us one and two yeah that would be good one length ones equals zeros I think something like this would also work for a more generic solution oh no it didn't quite work uh and then if we change the size to five look at that changed it to seven and this works because it's share uh it's square if we needed this to be a little bit more generic you could do like ones. shape zero I think and ones do shape one don't worry about the weeds here I'm just like going a little over the top here uh this the solution we had to start with was totally fine but I was just showing a little bit more sophisticated of a solution where like we had a dynamic variable I am curious if I create a new cell what is the answer here for 15 hint 15 okay and that's actually doing it a little bit differently that's a little bit easier than um length On's negative one this is also doing the same syntax saying go until one from the end so

Segment 9 (40:00 - 45:00)

that's another way to do it and then the actual answer yeah so they did a specific example um we just made a little bit more of a generic one right 16 how to add a border filled with zeros around an existing array so we have an array does it mean here that it's a one-dimensional array so we're going to just give ourselves an array we'll say that this is np. array 1 2 3 if we needed to add a border of zeros to that then basically our Dimensions is going to be two more in the X Direction so we need at least five elements in the X Direction and then because this is just an array we need three elements in the y direction so three rows five columns so np. Zer um of uh to make it generic three rows and then array I guess length array plus two um columns that's going to be our Matrix basically and then basically what we want to do is insert the array into that so it's going to have to go down into the first entry and then it's going to start from one to negative one and we're going to set it to array so hopefully this indexing all kind of made sense uh I can print out these individual elements so it is a little bit more clear and we'll then print the final zeros okay so we have our array we have a bigger zeros array that we ultimately want to insert this into and then we insert this in I'm curious what the hint here for 16 is oh mp. pad shoot we just did a manual solution uh when there was a nice elegant solution so I bet you the answer is a lot simpler yeah okay so this is a nice more elegant solution this also worked but this was a little bit not the most I guess numpy like but np. pad np. pad remember np. pad oh and we did kind of do this so this was kind of our solution in a similar way so there's no one right answer it's always interesting to see other people's answers too what happened here what the heck did I screw something up what is the result of the following expression 0 * np. not a number np. nals np. Nan holy moly I don't know can we just type this in or am I supposed to no up top my head like I would think that but like what am I doing it one at a time here are they or is it all in one go all right these must be individual expressions like they're bulleted I feel like this should be called Expressions maybe I would say 0 time np. nan would be just np. nan I'm going to just write down my answers but you could always just actually type in these Expressions so first I'm going to guess I think this is going to be npn n an I think this next

Segment 10 (45:00 - 50:00)

one H is not a number equal to not a number I just feel like this is going to be false just because like it's kind of like saying Infinity is equal to Infinity it's like doesn't really make sense I do think that this will evaluate to True np. n equals and I kind of think that this will stay np. n cuz it's not one set number I feel like this will be false or is everything false maybe like everything zero uh I would think that this should be definitely true that's my these are my final answers let's go ahead and run this stuff so I'm just going to copy these lines paste them in and run everything is f well I guess I need to print them individually this first one this last one's false that's crazy oh I could do definitely like a special thing in Visual Studio code to add this print statement to all these lines but I forget how to do that you can add multiple cursores somehow cursor I might actually look this up this is kind of cool add cursor to multiple lines vs code Ah that's a lot of things okay command shift down I think that's shift for control command alt okay command option down okay go back to visual studio code command option down down oh look at that and I can do print then I can go to the end of all these lines oh no this screwed it up I was so close I'll just add these manually that was kind of cool are these all false okay npn that's what we thought for the first one false good true interesting or false okay I guess this is just weird to compare these two um so that makes sense that this is false um n that's what we thought true uh I guess that kind of makes sense then this is false I don't oh oh okay is the equals evaluated first like if we added parentheses around this would it be true that's weird I find that very surprising that last one well this is the answer so ignore what I wrote orally all right 18 feel free to try this on your own and then pause when you want to see my solution all right so first we want to create a uh a 5x5 Matrix so we could do Matrix equals np. array 5x5 and then we want 1 2 3 4 just below the diagonal so let's just look at our Matrix first oh oops I should have done something like np. On's or like np. randoms maybe zeros is better okay and we want one two three four right below the diagonal so I'm going to just think if there's anything easy we can do on a uh number front so this is going to be we're going to have like uh array equals np. AR range uh to five that gives us oh I guess one to five okay so now we have our two things and basically I think we want to do Matrix and we're indexing at the same

Segment 11 (50:00 - 55:00)

time trying to think if there's a neat easy way to do this like I feel like if we just did something like array equals array would that make sense you know this one's like offset by one let's see what happens if I run this like that's close right but this one is offset by one so if we did array minus one I think that would shift it so just let's look at this again print array we get 1 two 3 four if we do print array minus one that's going to broadcast it I think that's the term that you say so it's going to be zero one two 3 as we see there so if we do array which is 1 two 3 4 that gives us one row with index two row with index three row with index four and then on the flip side it gives us column zero column one column two column three and then we set that to our actual array so I think that this is a pretty good solution pretty elegant I'm curious what their solution is so let's look up their hint this is 18 NP diag oh you can do an offset with a diagonal so that's another way to approach this and then so maybe I can try this real quick with the hint we could do Matrix just comma this code out real quick do Matrix np. diag what is the documentation here I think we can do matrix. diag and then we can do an offset does this work H not actually positive how it they do it okay it gives you the diagonal can get specific things from that can I do matrix. diag H I don't know interesting I feel like you want to set like k equals negative one to get the specific diagonal how do I set one though I guess maybe pass in Trix then I set it equal to array I don't know I'm going to leave my here and let's see what their solution is NP do or answer 18 zal n p. diag

Segment 12 (55:00 - 60:00)

one oh this is so interesting what does one that's just going to give us that's the same as this so it's giving us that oh and it's saying that that's the Nega of one term of our overall Matrix that makes sense uh it's like a reverse engineering thing but I'm also happy with our solution but I'll add this as a comment here so like we could have if we wanted to give our in terms of our solution we could do one to five here and if we printed Z we' also get the same type of Matrix see that that's cool all right create a 8 by8 Matrix and fill it with a checkerboard pattern this is pretty cool uh so I think first we want to do like let's do this zeros and ones so I'll call this like checkerboard equals np. z 8 by8 and then all we want to do is basically fill so let's look at our checkerboard we want to fill this one way this one way I'm trying to think are those all even positions not quite because this would be an odd position in that Row one thing you can do which is cool is like if we think of their overall index zero one 2 3 four five six seven eight um one zero one 2 3 4 five 6 7 8 uh we want one three I'm confused oh it shifts every uh row okay there's multiple ways we could do this I was thinking about flattening it but that doesn't actually quite work because it's not like All Odds or evens are um the ones here it depends on the row can you do the absolute value of the position so this zero even even if it's odd this is a really like kind of quirky thing we're on the Zero throw and there's probably a simpler solution um zero throw I'm going to use like the odd evenness of both of their Dimensions added together so zero throw row and let's say we wanted this one as a one zeroth row first index so that's our odd positions odd odd and then on this one we're in the first row and this is the zeroth index so first row plus zeroth column is also odd so if we did like np. where the checkerboard do shape uh do sum this is like a little bit quirky U mod two so that's divided by two equals 1 then we want it to be uh one otherwise we want to leave our checkerboard as is tup object is not callable can I do shape I think it might be this I'll double check in a sec oh shoot I need to do like each index

Segment 13 (60:00 - 65:00)

checkerboard H like this is what I want to do but how do I make this I could make a array of their indices this seems like I'm over complicating it though I could just run two commands I could do from on the row side uh we're g to do we're going to add ones to the rows and then that are odd and then ones to the rows that are even so we can do something like NP do checkerboard so that would be stepping over all rows looking at all columns by two then every other column starting with one to The End by one um we're going to set this to one and then starting on the other rows so starting with one going by two does this work two uh and then the even spots here so oh I guess this is probably every other like this we want to set this to one and now if we look at our checkerboard look at that okay that wasn't too hard I don't know why I was over complicating it um so this is getting every other row and it's setting the odd spots to one this is getting every other row starting with the you know second row first index and setting every even spot to one let's look up the answer here yeah they did exactly what we did they specifically specified ins that's not super important though okay consider a 6 S8 shape array what is the index XYZ of the 100th element so that means each row is a 7x8 array so the first row 7 * 8 is 56 um so it's 56 elements it's not going to be in the first row it's or not the zeroth the first row because if every row is 56 elements then the second row first index is going to be include the 100th element because there's going to be 112 elements in those first two rows of matrixes one and then we got to think by the row and column of that so we have in the second thing and then this has if we look at each seven by eight that means seven rows eight columns so we're already 56 elements through and we're going to be like a little bit off by one here I feel like with how we think about this in our head but 56 elements through and then we're going to have seven rows in this thing with eight columns so we need to get to the 44th spot uh so the 44th spot is going to happen uh first five rows have 40 elements the sixth row is going to contain that 100th element and it's going to be the fourth spot in that fifth row I might be off by one here so five and then the fourth spot so this is 56 This is 40 we're at 96 and then plus 4 is going to be a third element I believe the fourth

Segment 14 (65:00 - 70:00)

spot I think it's going to be we can try this NP do a range from one to whatever one six times 7 * 8 do reshape 6 7 8 curious what that would give us now we're so close this needs to be zero okay and so if we then get the 153 out of that should be 99 look at that it's 99 so I'm going to say the answer is 153 Final Answer 20 okay well it's telling me that this is the answer 153 cool so we got it I didn't know how to I guess I don't know how this is oh that's kind of cool so this could give you the index if you need the 99th spot from a 6x7 by 8 it will actually tell you the index I had to do it with manual mental calculations in my brain so either way it works okay create a checkerboard 8 by8 Matrix using the tile function so real quick let's look at what the tile function does I'm going to do an array of two elements or maybe we'll do like three elements 0 1 two if we tile this I think we have to do np. tile I don't think you can do array. tile yeah np. tile um if we did it with array and then let's say like five times god what happened ohay uh we see that it goes one 012 012 012 so to make a checkerboard I would say we should just do 01 and then 8 by 8 is going to be 64 elements so if we do this 32 times Watch what it gives us and then if we just reshape this to an 8 by8 that should give us a checkerboard oh not quite a checkerboard how do we fix this off by one issue here is there any other functions in this tile like the cheating way let's just see what other options we have with our NP tile I think it's these two functions yeah just two things what we could do though is NP tile for like I'll call this odd rows odd row even row would be equal to MP tile we could even use the same array and just do it in reverse which is this uh by four and then we could stack the two on top of each other four times so like we have the odd row then the even row is going to be the one start uh and now we just need to like

Segment 15 (70:00 - 75:00)

combine those can I do this odd row even row I could honestly do np. array odd row even row and do this four times right reshape AP by8 how does this look oh no it's the same thing uh for so is there an Axis or something I can add this to because it's adding them oh maybe if I surround it with another parentheses here to like make them more together that's strange I mean I thing is ah the thing that's frustrating is I could do np. repeat four times and then reshape it and this would work maybe not what am I missing here so that's adding them all to this can I reshape this in a different way like need to Con cat them so if I did like plus I just don't know what function use and whatnot for what happens if I reshape this that works I don't know okay the issue is they were separated before I just when it says using the tile function I don't know if that means like don't use any other functions so the

Segment 16 (75:00 - 80:00)

hstack like horizontally attaches these things so if we look at just this printed out we see we get like this looking thing and then repeating that like does what we need we repeat it four times or tile it four times uh and then reshape it and that makes sense why it works uh I just don't know if H stack is acceptable in this case so I guess we'll just look at the answer we did use tile oh interesting oh you can tile with a shape here 4x4 so it can go in both directions interesting okay good to know so this is a matrix it's you know tiling those okay that definitely makes sense you live and learn 22 normalize a 5x5 random Matrix so normalizing a matrix what does that mean uh it means like get everything to add up to one I believe on rows or columns let's just double check that normal what does normalizing a matrix mean yeah scaling its values to a range of 0 to one this is done by dividing each element of the M yeah I haven't done linear algebra in a while and then you can go down a rabbit hole of what is a determinant okay so it's for normalizing RX okay this is how you calculate the determinant there's a little bit of an aside we're getting really into linear algebra here so if this doesn't make sense look up linear algebra but let's take a random Matrix so and I'll make this 0 to 10 and a 5x5 a equal or call this Matt equals this I will

Segment 17 (80:00 - 85:00)

give this a random seed we got Matt here okay now if I run this again we can see that it doesn't never change okay so getting the normalizing it I bet you there might be like a Norm np. Norm I guess not but we could do matt. determinate or np. deter H how do we get the determinant of I'm not going to like do the like there's definitely a mathematical process here I really would think that there would be like a determinant function is a the determinant all this is I'm just going have to Google determinant in numpy okay there's a linear algebra. determine good to know we do there's also a linear algebra. Norm function we're learning np. linear algebra. Norm yeah we can pass in Matrix here um Matrix Norm Matrix okay I guess I'm going to just do determinant of that and then we'll just do Matt to TI by that I guess this is the normalized Matrix this is element wise division by determinant I would think that there would be a one liner to do this but let's just look at the hint I mean if I needed to do x minus mean that'd be minus matt. mean all divided by matt. standard deviation I would want to make this in parentheses I don't know if that was the same exact value we'll print this too just to check okay not quite the same value okay so I guess this is how you normalize it let's look at the answer man I really need to review I guess I just don't use the linear algebra a ton these days okay now we got it right um You can also call you know mean and call standard deviation so that's just slightly different way to do it create a custom data type that describes a color as for on signed bites and I don't know how to do this

Segment 18 (85:00 - 90:00)

so four unsigned bytes is going to be u four I don't know how to make this so for do this one 123 sorry gang when just have to take the hint you know this is something I definitely feel like would Google what happens I do like rgba equals np. dat type the u4 would be unsigned for bytes and it like seemed like that was an autocomplete option that's my this is my final answer let's see what uh the answer is to 23 I never had to like I've never worried so much about having it like performance being so I guess maybe I don't want to say never but I feel like I find it very rare in my day-to-day I'm not you know I want things to be fast but I don't need to be so performance optimized where uh literally I'm only using four bytes to represent our like rgba like if I use a little bit of extra bytes um totally fine and just to make this clear like each bite is um eight bits all of zero or ones so it's basically just saying like you're representing the rgba uh what does the a in rgba stand for red glue green blue what does a in rgba mean stands for Alpha so that's the transparency opaqueness so it's basically saying that we're representing rgba in this format which makes sense because you don't really need any more than this each bite 2 to the eth what is and like you know that rgba is 0 to 256 I think 2 to the E is 256 yeah okay so that's why you're making a custom type like this I think that this is probably the solution let's see answer 23 oh interesting I don't know this is not something that I've had to deal with but I guess cool to know 24 multiply a 5x3 matrix by a 3x2 matrix okay one thing that's nice to know about matrix multiplication is that uh when we multiply them we want to make sure that the middle values so the three and the three are the same value otherwise it doesn't work to multiply them and then our resulting Matrix will be uh the outer Valu so it'll be 5 by2 two so we could do MP do how about ones

Segment 19 (90:00 - 95:00)

of uh 5 by3 and then call this a b equals np. one's 3x 2 and then Cals a * B we can just do it like this if we look at C it's going to be I think we actually do dot matrix multiply np. Matrix multiply a comma B it's trying to do some weird other stuff now we look to see uh get three 3 three and if we look at A and B real quick I'll just do like one entry print a print B uh this is 3x5 so basically what we're doing is we're going this row and uh this column so 1 * 1 plus 1 * 1 + 1 * 1 look up matrix multiplication if you're not familiar but that equals three and then basically if we just repeat the process so now this ones with the second column we get the next three we basically just repeat this process that's how we ultimately get all these threes but all we really needed to know about was this line right here we look up hint 24 but you'll see is there no hint for this one answer 24 there better be an answer NP dot this is also okay they're saying do a DOT product but there's also just this matrix multiplication function but these are the same curious difference between dot product yeah so dot product is just on a scalar value but Matrix modification is a bunch of dot products so I'm happy with our solution here given an array a 1D array negate all elements which are between three and eight in place so I'm going to do that array equals NP do well random. randint how zero to 15 with a size of how about I know 20 so we got something that looks maybe I'll just make it like 10 elements got something that looks like that I will seed this just to keep it same this stays the same okay so elements between three and eight are negated I think that's inclusive so this would be negated this is this is negated and that's not negated so all we need to do is just do array we can do multiple expressions in this so we can do array is greater than or equal to three and array is less 8 and in those conditional spots we want to set the value equal to oh we just want to negate them so I might use an mpw here I'll say negated array equals np. wear same conditions array greater than or equal to 3 and

Segment 20 (95:00 - 100:00)

array less than or equal to three uh when that is true or less than or equal to 8 when that is true we want it to be dot I mean array times1 basically when it's false we just want it to be array look up the negated array and so if we looked at these together we see looks good trying to think if there's a better way to do this is there just like a what does this do it looks like that works as well I'm curious if we could have done this without the mp. Weare what would happen if I just did array with this condition equals array Dot I don't know if that would work I think we might have to do the mp. Weare let's see the hint here this is 25 let's look at the answer times equals that makes sense and. Weare one works as well this is weird range five minus one I feel like the it probably errors out on the first one I don't think you could minus one from a normal array but this then makes a nump array minusing one is going to be1 okay so I think the first one is an error and then I think the second one we get Range Five is going to be 0 1 2 3 4 but Range Five comma negative one what does that do I'm really confused here what would a sum function what would be the negative one axis oh Counts from last index to First index so it it's like reversed order that doesn't really change anything so it just so I still think the sum is just 3 6 10 I think it's going to be 10 to the second one okay so this is what I think we're going to get oh interesting I guess this does oh okay I mean we're not minusing one that's where I was getting tripped up what does this the normal sum function do oh now we're now we have this import Star at our nump by no uh I might like restart a kernel here because I don't want all the right if it restarted correctly then I can't access nump

Segment 21 (100:00 - 105:00)

okay n p not defin that's what we want okay I misread this one it should be nine and 10 consider an integer Vector Z which of these expressions are legal um this would raise all of the elements in Z to some power of Z that would make sense what does the shift do oh man I think this is fine I don't know what yeah call this Z okay my predictions are valid legal we say this is legal I'm going to say this is illegal I don't know why I'm going say this is legal I'm going to say this is I think that these might be bitwise shifts here so it's saying shift it I think that this is also maybe legal I don't know what this one does well we'll find out are interesting things so start with running this I guess I can't even run a simple one all right so let's just look at Z real quick okay that's an in integer Vector I would say Z to the power of yeah that's oh I guess should see this again so we know what we're talking about look at Z okay so six to the six power 3 to the 3 power is 927 so that's when we do this we do c27 there that is legal let's see what happens when we do I want to print Z out so we can see both it and the transformation Z 2 I feel that's just going to leave it as is what did that do oh these might be bitwise shifts I'll figure this out I'm like talking to myself right now but maybe it's kind of interesting I don't know like what happens if I just do the first one here I mean it was a legal expression so at least we were right this seems like a what does mean in gomai bit shift operators left and right oh interesting okay I'm GNA I'm G to explain this what's going on here so if we bit shift by Z and this is our Z and we start with twos so basically let's just say we have a

Segment 22 (105:00 - 110:00)

bite I'll start with just one value but we have two basically what we're saying is we have twos all along if we're shifting bitwise a left I would say this is a left shift by Z so this would be a two in binary if we're left shifting by six for this first one this would be two 3 four five then six so this is now one and this is a zero how do I add too many values and so this is now let's think this was the one shift two shift three shift four shift five shift six shift okay so now we have two to the 9th what is or it would be a six shifted left to we'll find out think two to the 9th is definitely greater than 128 so six would have been one two shift that too there be that' be one two 48 16 plus 32 48 that's weird h let's go back to that dock hopefully what I was showing kind of makes sense I should be able to at least get an answer left shift two left shift by six 2 to the 6 is okay that would be 2 to the 7th where was I getting two to the 9th okay go back to that first example we got zero here we shift it by six right it looks like this is the zeroth index first index second index third index fourth index fifth index sixth index seventh Index this is 2 to the 1st shifted by 6 7th I don't know where I'm screwing up exactly 2 to the 1st 2 to the second third fourth fifth 6th sth okay two to the 7th that gives us 128 if we then shifted two by three one we're going to replace this one two three this gives us first second 3D fourth fifth two to the 5ifth is 2 * 2

Segment 23 (110:00 - 115:00)

is 4 third is 8 fourth is 16 first second third fourth oh 2 to the 4th is 16 yeah that checks out here and then we can shift it the other way too which is what we're doing here pardon that aside I don't know if this note makes sense but this is the first ex example that's what I was trying to show okay keep going is this legal what does that even mean I don't know what this one means operator in numpy you could also use like chat GPT or something there is no why is it working did it maybe get added or something so we said legal legal legal this one should just be all falses let's just try these other ones first though one J * a this is uh converting it into imaginary syntax I believe this is good stuff to probably like throw into chat GPT but that seems legal Z ided one divided by one that should give us just Z yeah does and this last one Z is less than Z which is greater than Z they should just be all falses oh interesting that one's not legal okay I'm really curious about that one operator though so I'm gonna I'm going to pull in chat gbt that's so weird why did it not fail I guess we can just look at the solution

Segment 24 (115:00 - 120:00)

maybe does it not give us any answer I'm so confused let's just skip to the 28 these are tough I have no idea about this one like np. nan as type int as type float strikes me as 0. 0 for the last one so array divide by m array I feel like this would be like error floor divide by zero kind of feel like this one's going to be zero and 0. 0 let's try print n okay that makes sense it's not going to error out it's going to give you an N that makes sense this might be an N too Honestly though oh it does give us zero I wonder why the floor div divide gives zero because if you divide by any number 0 divided by seven is going to be zero I don't know what the deal is with that I'd have to get into the specifics there let's see what this gives us oh guess it's to be an MP array of 0. 0 yeah so if that makes sense so this was an how to round away from zero if flow I think this would be ceiling or something like we want the ceiling and take an array goes np. random. random make this like five number array and if I do array. seal or np. seal of array this should all be one or this will be all ones here uh and like you could do that for any like if we did five times this it'll be random values but this would round one or round away from zero yeah NPC is one of them let's see the solution that they give oh okay so it wants you to round away from zero with absolute values as well okay that makes sense so use the ceiling or use the ceiling based on uh whether or not it's greater or less than zero how to find common values between two arrays so if we have NP there's a nice little function for this so we're going to do np. a equals np. how about a range 0 to 10 this next one's going to be np. ar range 5 to 10 so we'd expect the common values to be five six 7 8 in N we can do a do intersect or I guess we have to do np. intersect

Segment 25 (120:00 - 125:00)

1D a comma B and that gives us what we expect so that was pretty straightforward let's see what they said for the solution though yeah intersect 1D cool how to ignore all n by warnings not recommended uh I think you're going to use mp. warning what does that do H if I really needed to do this what I would probably recommend like if I was using cop or uh my Jupiter notebook I might do command I ignore numpy warnings just see if it auto completes this set error all equals ignore I don't know if that's right I guess it would ignore everything but that's warning so I wonder if there's a p. set let's like just floating Point errors like things like this I wouldn't expect to know off the top of my head I want to see the answer okay it was what the gbt or GitHub copot recommended I did co-pilot I have GitHub co-pilot like I pay for it I guess so that's why I'm able to use this chat so I do command I to open it if you do have it but um NP I guess I don't really want that though because now we're going to be screwed so I'm G to restart the kernel just keep that commented out what is eath oh man I'm guessing that's like imaginary math so I think that this is going to give us an error so I'm going to say that this is false because the one's going to be an error and one's not so I'm going to say no it's not let's see I'm going to say false np. false cool and I think it's because we do get this runtime warning so this is an npn but because I don't know what exactly eath is um yeah I think that this helps uh translate things so if we look at what happens when we do this so we'll say like Val equals this we look at Val we get a complex number but when we just do uh np. Square t negative one want to get like an error and if I did like type of this it's just G to be

Segment 26 (125:00 - 130:00)

like I guess it stays a float 64 it just can't represent this so I feel like it's ultimately like an N I would think but the nice thing is the type of the Val is this complex number so emath helps I guess translate to the proper types that are more easy to work with get the dates of yesterday today and tomorrow NP dot I guess we probably do np. daytime 64 I bet you there's like a date time I feel like I'm kind of going a little crazy so I'm going to get some like chocolate or something I'm a man of uh class I got this dark chocolate this is going to power me through at least another 20 also fun fact was like I probably will film maybe I'll film this over two days probably will wear the same shirt to like hope that no one notices but I'm telling you guys this so now you know secret surprise that was pretty good that was quite good I'm a fan of that chocolate all right is there like a date Library I'm going to just look up date time like because I would normally do like import date time uh date time do like UTC now I think be something like from date time input for date time and now there's probably a function datetime do yeah UTC now I guess this uh I'm guessing this means it's deprecated okay it just be dot now like I would do this and then I would do like uh date time dot I do like a equals daytime now then I'd be or like today equals datetime now yesterday equals date time. now do I think I could do daytime. subtract oh okay so I do today and then date minus date time. Delta is there a time Delta function Delta days equals 1 that give me yesterday similarly I would add for tomorrow and if we printed all these things print today yesterday tomorrow is equal to today plus time Delta days equals one and you

Segment 27 (130:00 - 135:00)

can set this Delta to have all sorts of information this is a very useful function print tomorrow run that uh so you need to know when I'm filming see see and the print is nice cuz it nicely formats it for us but that does all look right but it's not asking us how to do it in date time Library land numpy and I do not know date times in numpy so we are going to get date time of today in numpy I wonder if this is just like to how would I know this let's just look at the documentation here num. time 64 I want to see like the values like how would I know anything about this I would look up I guess like numpy date time 64 Docs uh I'm really confused like does this work that's crazy how would I know this where is this in the docks I'm G to Google this specifically I'm just so confused like numpy I don't know but we learned something new somehow it's in there I just feel like daytime get today's date numpy I'm so interested by this I don't know well interesting but we can use this to our advantage what if I

Segment 28 (135:00 - 140:00)

did dot doc here okay AR raise date time for more information I'm done looking at we know that we can do to today so we can do today equals np. dat time 64 today to yesterday or equals today plus np. time Delta and then we can pass in one DayDay seems like we could do just print today and print yesterday which I guess I accidentally put as tomorrow it was yesterday it should be minus uh and we need to know all the codes here but I can imagine like you know this is months so if we added one month or subtracted one month this would be 930 maybe it's lower case M or one minute maybe uh what is we could definitely look up Dr here Z go to Doc raise date time dat daytime units here we go month is m capital M weak is w m is minute lower okay so we should have been able to did a Time Delta like this with a capital l right then printed yesterday oh I don't know what the deal is here okay well this would be our results but I'm curious to see the answer here should be answer 3 three yeah that worked okay I don't know I just don't love this I would I feel like I would do something more similar to this if I was to do this in the wild um yeah it seems weird to me a little bit not like super friendly I feel like pandas has simplified that enough how to get all dates corresponding to the month of July 2016 I feel like we're going to do something like July 2016 equals np. date time 64

Segment 29 (140:00 - 145:00)

let's look at the docks again here if we could do something like this and if we did 2016 and then July I always forget these dang dates uh July is uh January February March April May June July 07 right what does July 2016 look like yeah I mean I could very easily like 30 days have September April June and November all the rest of 31 so I could very like I could very easily do like I feel like this is super messy hey could do something really ugly like this that does not work this is like zero paded for this is gross I need a hint I'm tired I need chocolate oh wow I could probably do something like mp. a range this value then I don't know what oh man I could do 01 as the

Segment 30 (145:00 - 150:00)

start then 31 is a stop that's like I guess the stop would actually be 801 that' be August 1 because you want it to be exclusive look at that that's cool didn't know that now we do cool let's see what the solution says okay cool that's pretty neat you learn something new every day oh my gosh I need more chocolate I'm crushing an energy drink right now too wired back starting to hurt a little bit oh no the chocolate ah getting I'm getting chocolate on my desk I wonder all right I need to burn off these chocolate bars I don't think you can see me though if I do push-ups can you see kind of one two three four five six seven 8 9 10 11 12 13 14 15 16 17 18 19 20 all right 20 push-ups I earned more chocolate I swear God gosh all right we're ready to go we're fired up all right I think this is with matrices how to compute A+ B times a I'm confused by this one how to compute a plus b * am I missing something here for I'm confused like is that fine then this would all be in place I'm not copying anything I'm so confused by this one I guess though maybe a would have to be the same like if I printed out just a it shouldn't still be one 2 three

Segment 31 (150:00 - 155:00)

4 I did np. add I guess I do Falls here or something okay so the output needs to be stored like it in a certain place I can't store it in a because we need a afterwards so we could store it in B I wonder do I need to like surrounded in quotes oh yeah we need to make sure order of operations are as held and negative a I think I can just do this two and the ult multiply is ultimately like this can be stored in a like we have to make sure it's okay so this is done first stored in B then this is done which doesn't depend on B so it's stored in a and then we're multiplying b and a and so the output of that then can be stored in a we'll just make this a data type we float 64 probably need to make this uh float 64 as well look at that I believe that that's good let's see the answer so it's basically like we need to just use the memory we've already allocated and that's what we're doing here and because we only have two arrays to work with we basically have to be smart with our order of operations and then copy our data in only when we're done with that output because this one still depends on a later on we first save it to B we'll look at the answer though real quick NP add output B NP divide output a NP multiply up put a so they we just did it in one line they separated it but cool to see oh the negative H I wonder if that matters so I guess technically this should have been NP negative okay this is really if you're caring about every bit of memory feel like we are live in a lucky era where this doesn't matter as much extract the integer part of a

Segment 32 (155:00 - 160:00)

random array of positive numbers using four different methods so I think what I'll do to oh we got to just extract the integer part so like if we have 5. 5 uh what I'm going to do is np. random. seed just to work with something and then I'm going to do np. random. random do size 10 let's say but we'll multiply it by five call this array and then if we look at our okay so we want to get just the integer part of this so like four in this case two in this case um so the first way I think of doing it is uh we do array floor divide by one right because if you that will just give you the value anything divided by one is still the value but the floor divide gives you just the lower bound so it gives you the um integer part right 42 4 3 three cool that looks good uh we could also do and I'll just print these so floor divide is one way to do it we could also do this the floor print array. floor or I could to do mp. floor of array then we get that same thing that's two methods so method one four methods is a lot of methods two uh method three will do this + one minus technically I'm not it's a different way uh but I think that would be a little bit cheating plus one minus one watch and learn look at that all right we will not do it that way though I'm so clever all right what else could we do I mean you could do the ceiling and then minus one I don't know if that counts NP do seal array minus one that would give us the same I think that's like a valid enough method I'm trying to think if there's another good way here I mean what happens if we just cast it to a different data type I wonder if we cast it to integers uh array do cast or what happens if I do this as type int 64 or int 8 honestly is fine uh that's another way I'm pretty pumped about that that's kind of a cool unique way to do it as well Ah that's pretty good I'm happy with that trying to think if there's anything else because we're just I'm pretty happy with that what would be the solution here answer 36 floor we did that as type we did that divide we did that Z minus Zod one trying to think how that works zmod I guess array mod one would just leave the remainder okay that makes sense that just leaves the remainder of the array

Segment 33 (160:00 - 165:00)

if you're dividing by one so if you subtract that from the original that makes sense so I feel like my ceiling solution was kind of cheating but I wonder what the trunk K method here does np. trunk okay so it's closer to zero than X's so it always goes downwards I mean this is just a range five and then we just do np. repeat I might have to broadcast this too I can do the transpose uh so the transpose is like if I go back to the original is making is flipping the X and Y coordinates so if this is row zero column 0 Z row 0 column 1 then when you transpose it this becomes um column zero Row one so that's why this transpose Works trying to think if there's any other ways I think I mean can I just tile it too yeah tiling works as well let's see what the this didn't seem that hard oh I guess then I could use the this could be done why is it 5 by one but there's different ways you can play around with the tile function doesn't say anything about not broadcasting though so I'm fine with what we left consider a generator function that generates 10 integers and use it to build an array I mean this is just what I've already kind of done zero down 100 and this build 10 I'm fine with that I'm wondering what the answer here is oh they actually wanted a generator okay well that's good to know create a vector of size 10 with values ranging from 0 to one both excluded I think that this is just np. random. random I guess zero can be included in this uh what is random sample how can we exclude Z I mean zero is never going to be actually included with random. random I feel like maybe this is a wording

Segment 34 (165:00 - 170:00)

issue like even though Zer included that set I don't know how you do both excluded there must be like another function that is a hard cut off so I don't know if people understand that issue that I'm seeing it's such a minor issue when I do random. random uh this specifically half open interval that zero means inclusive 0. 0 oh okay we could do a trace or something like that mp. Lin space zero one five mean I can do something like this but I don't know what they want me to do for excluded here this is just like up to my interpretation I don't know I'm going to I also would do the random stuff but I'm not sure what they're looking for what's the hint here okay I did Lin space I'm curious if my answer is acceptable they need to be excluded so I did values close what if what is the answer there's an end point equals false interesting 0 one what is n point2 that's crazy and so it doesn't include I don't know this is a weird one I I feel like this is very Niche so it's not letting me create a random Vector of size 10 and sort it random a equals Rand or np. random. random1 and we're going to do is there just an a. sort yeah oh mp. sort np. sort a that looks good to me I could probably do this in place too I looked at does np. sort do it in

Segment 35 (170:00 - 175:00)

place uh no it does not it does make a copy is there an in pleas for how does sum a smaller ray faster than MP all right how to sum a small ray faster than mp. sum eight that's this is weird maybe cumulative sound me I could just do ad out sound I mean I suppose that would be faster maybe a. yeah I don't think that would be faster I mean probably indexing it if you know each index what is a hint here mp. add. ruce I want a solution or maybe let's look at the documentation there np. add yeah I feel you really have to know the weed to know that this is going to be faster for small arrays uh that's unfortunately not something I knew so the solution would be I don't know why that's faster you probably could Google and like there might be discussion threads on this um GitHub repo all right consider two random oray A and B check if they are equal right so let's just make two equal

Segment 36 (175:00 - 180:00)

arrays so if we just start by doing a equals B what happens so it's true true true because it's going element wise I think we can do a. equals or np. a comma B same thing if we said axis s axis column here what we can do what I do know as a solution is you can do something like a equals B I think that's equal to np. equal and then you can do np. all that should give you a true or false and if you really wanted to convert it you could do something like buol so if we change this to like an eight false change this to a 4. 0 it should be still true so mp. all checks that all of those values are equal curious what the solution says though all close here's what happens if I do np. array equal okay so I guess this is similar but it's probably something along what we're doing here let's see what the solution says this is cool I wonder how all close works relative tolerance and absolute tolerance it's pretty cool so if we had something like np. all close AB it's going to be true by default if I change this to 3. 0 it's not going to be true but if I said absolute tolerance is equal to two it's going to be true then if I change this to like eight it's going to be false that's cool it's a useful function make an array so immutable means you can't change it at all read only lights turn on uh so np. I'm be guessing there's a parameter here one two three and then I'm guessing there's like a special type of

Segment 37 (180:00 - 185:00)

array h for interesting I'm going to do a little co-pilot chat create a an immutable array in numpy I would never have known that without looking it up but good to know so now if I try to do immutable array 0 equals one we probably should see like an error or something yeah that's cool flags. WR up interesting so let's see answer 43 and you know I am using compilate chat sometimes I think that like with this type of thing there's certain things you can kind of piece together and figure out logically but like something like this you either know it or you don't it's hard to like just get to it so you're going to have to look this up so co-pilot chat is kind of my short hand for looking it up and look that does show the same thing a random 10x two Matrix representing cartisian coordinates so we could do something like random. randint so if you think about cartisian coordinates to Polar coordinates give you a Theta and a radius um caresan is like your classic XY um this is another thing in math that uh you know it's been a little while but we can start with our at least our Matrix I want to see if I can piece together this okay so this is our coordinates so the way we need to change our coordinates is we need to create a new array the radius is going to be uh Pythagorean theorem so I mean I don't know how the easiest way I can like show this it's like we have this axis right so cartisian coordinates is XY so like you know you're going this is so hard to do while my hands are up uh you know I don't know ah this is not working either let me just type on the screen why does it keep copying that when I try to do three codes so we got this little

Segment 38 (185:00 - 190:00)

axes okay so that's our axis so we need to figure out like we're given points right now like a point right here and that would be like x equals or 3 Y = 2 but now we want to find the radius so I'm kind of trying to draw radius with my mouse cursor so that would be you know one unit squared plus the other square root of that so coordinate one would be I think there's probably like a magnitude think we do mp. linear algebra a. mag magnitude how I get magnitude would that be the determinant of the okay I'm going to just I want to get a 3 four five triangle real quick does this give me five you can't do determine it there magnitude sure then to get the angle we have the X and the Y so it's going to be is there math package mp. maath np. maath maybe eath I don't know we're going to have to give you some soaa here so two things going on sign we have the X and the Y the angle we need is opposite over adjacent So Tan theta equals opposite is our y overx so Arc tan y over x equal Theta hopefully that kind of makes sense and the other value is just x² + y^ squared and then the square root of that equals R so how do we convert these np. power oh man I'm tired for

Segment 39 (190:00 - 195:00)

all right so magnitude like I feel this is like a list comprehension but I feel like that's not num numpy esque so like if I wanted to just get the AR tan thing I it looks like I could do numpy emath Arc tan how is it it's not Arc tan what is r tan versus tangga 1 R inverse tan and tan Arc tan the same okay so we were good right here should just be one value for okay we're getting there np. square root np. sum this would be axis equals one or something like that okay does this make sense okay it's this okay that is the RS and then how do I get the arc Tans np. divide I mean this could be like mp. divide the first elements should be iterate over each row grab the zeros for everything divided by array one and that work grab rows you want to grab every row okay sorry you get every row this way and then you grab the zeroth element get every row this way and grab the first element and then I could just do

Segment 40 (195:00 - 200:00)

this okay we're good is that y overx though this should be is the first is the Row the first one row row is that's XY oh X comma y so Y is second this is first okay so that is y overx so then we want to do NP do Arc tan of this and then we want to do an MP array of p. concat R this is our Theta equals I screwed something up okay and then new core polar chords equals r something like this print polar cords not quite there I want to do axis maybe I do H stack I want to do piecewise it's like a zip I is there np. like in Python I feel like I do R Theta I could like do a numpy array of this I think it's zip right zip R array with Theta array in numpy column stack oh that makes sense that was silly I'm just getting tired that looks good this seems that's R that's Theta I wonder if there's a better way to do this all right h int 44 what is the difference between Arc tan and arct tan 2 but I think that we probably got it let's see the answer of 44 random X comma y this is our y right x x comma y np. sare root okay so they just did a little bit more um that makes sense to do it like this but it's the same thing

Segment 41 (200:00 - 205:00)

um we did the MP to sum after that cool uh oh they didn't they got in polar coordinates they didn't zip it back together though so we took it even a step further with this column stack H all right create a random Vector of size 10 and replace the maximum value by zero okay array equals np. array or NP I don't know random. Rand int I just do mp. On's size 10 I'm going to put a random uh 100 in there print array okay so how do we replace the maximum value by zero but we need to do it in a dynamic way array. ARG Max what happens if I just run this okay 0 one 2 3 four five so then if I do array do and index array. AR Max equals zero what happens to array look at that that's pretty good what happens though if I have multiple 100s so that's see so you could do a two-step equation here too if you did so this works for one single value so it replaces the two in this case if you wanted to replace multiple you could do something like uh Max equals array. Max NP array equal np. where uh array equals Max where that happens where that's true zero otherwise keep array now if we look at array both of those spots are replaced with zero so two ways to do it um if only one instance and you could even make this a oneliner and do array. Max um if multiple equal Max values I'm curious what their solution is though 45 yeah so they use the first solution what does this even mean create a structured array with X and Y coordinates covering the 0 to one okay so it just wants like a bunch of random values between zero and one so I would say this is just like random. random and if you wanted XY coordinates this is size I would do something like 100x two and this gives you tons of coordinates to work with what does the answer say or hint even what is mesh

Segment 42 (205:00 - 210:00)

grid just look at the answer I don't know if I understand this right like this would also kind of work I don't know if it once like things so I guess I wanted evenly spaced things what is the mes grid what does Z look like interesting given two arrays X and I construct the Ki Matrix such that CI J equals x IUS y so we got an array got x equals np. aray let's say 1 two 3 4 y equal np. array we don't want this to be divided by zero 8 9 10 11 we won't run any divide by zero errors there but maybe we make this just two-dimensional okay so this then has a dimension of I are corresponding to rows or I guess X would be Tech h because we going to have a 2x4 construct basically our Matrix C then is equal to I want to just look up Kashi however we pronounce that Matrix just want to understand the dimensions here for some n by n sh

Segment 43 (210:00 - 215:00)

so x0 would be one X1 is two like I need to like use two four Loops for this equals length x length y let just print out C real quick I feel like it's the other way right feel like X should be I feel like it's going to look like this for I in range X for J in range why this is like very not numpy though C I J equals 1 / x minus y j that's capital now look at C is there a better way to do this only what that dude index two is out of bounds for we just saw that was right so this row what happens if I do J comma I oh okay because there's only two rows there's four columns that makes sense is there a better way to do this I don't know I'm happy enough with this let's see the hint np. subract outer holy F holy moly I am hitting a wall I'm not doing these well huh subtract outer why is it giving it the terminant I don't know

Segment 44 (215:00 - 220:00)

all right I think I am okay I think we can do this minimum and maximum rips is there a I'm cheating on this one we go GI up co-pilot did command ey that's pretty cool it's not fair how good some of these h what the AI tools are that just worked so quickly uh how to print all of the values in Array np. array you can just do print a like what happens if I do a range 10,000 a. 4 I mean I could very easy do a for Loop over it can also do list a that gives me everything I'm happy with that solution there was to scroll through this it would give me everything uh hint 49 okay so I guess this is like a more generic solution there's probably some way to like print like let uh print show more items by default okay so threshold would be a th but if we set that to a higher you can also do cy. Max size cool so print out the documentation I didn't really understand this one how to find the closest Value to a given scalar in a vector I mean if you subtracted that okay let's think you would want to take the absolute value so we have an array np. random Rand in how about 0 to 100 values if we have a scalar that's equal to five if we and maybe we made it like

Segment 45 (220:00 - 224:00)

negative 100 to but it doesn't even matter basically you want to take the absolute value difference so you do five if you're minusing things from the array 5. 25 we should expect like five will probably be the closest but if we subtract scalar minus array okay we get all the values we want to take the absolute value of that and then we want to take the floor or ar men and then we would index the array by our B yeah so that makes sense it's five in that case if I made it 5. 75 we expect probably yeah like a six but I feel like we ran it enough we might get a case where yeah it's like a seven or four cool so we have to do the absolute value because it could be yeah we want the absolute values distance to be the smallest um hint 50 yeah argument Works let's see what the answer is absolute value Z minus V argman we did the same thing we just they called that dot ARG Men We did np. argman and then we indexed it like that so we're good all right gang um I'm pretty tired not going to lie we've done 50 problems and I feel like it's been I don't know like close to five hours I don't know when all said and done with when I cut out the you know the random parts of the clips where I was just like Frozen uh probably around five hours we're going to go with that uh I think just so I can get content out more quickly I'm going to say we're done with this part we did 50 of the 100 and I will release a part two either next Saturday or the following Saturday um where we do the remaining 100 and I know that I mean they have the relative difficulties in these star ratings so I know that it's only going to get harder uh with a lot of these um so I think that uh for sanity and for getting good content out when I'm fresh and whatnot uh we will plan to do the remaining 50 problems in a part two uh if you enjoyed this part one throw it a thumbs up if I should tweak things for part two let me know uh happy to do that uh let me know in the comments uh when part two is up I'll make sure to like pop it up at the end here subscribe if you haven't be quiet phone um yeah D honestly like that's a lot of staring at code but it was fun we had a lot of fun here we had tons and tons of fun python is cool I so I'm still sayane we're still sayane all right I'm crazy all right just a little um all right we're going to try that again thank you all for watching hope you enjoyed this first 50 problems if you did throw this video a thumbs up subscribe to the channel if you haven't already let me know in the comments ideas for future videos part two coming out fairly soon maybe I even make it a part three I think that we can squeeze the next two next 50 problems in a part two so I'll make it a part two um yeah till next time everyone peace out

Другие видео автора — Keith Galli

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник