Beginners to Advanced NumPy | DevTechie Interactive | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

25 Lessons (1h 16m)
    • 1. Introduction Numpy

      0:13
    • 2. Who This Course is For

      1:02
    • 3. About This Course

      0:44
    • 4. Tools

      4:04
    • 5. What is Numpy

      1:03
    • 6. Brief History

      0:47
    • 7. Why Numpy

      1:40
    • 8. Concepts

      2:16
    • 9. NDArray

      4:56
    • 10. Basic Operations

      5:08
    • 11. Matrix Multiplication

      2:52
    • 12. Increment & Decrement

      1:10
    • 13. Indexing

      5:27
    • 14. Slicing

      8:37
    • 15. Iterating Array

      3:01
    • 16. Conditional Boolean Expression

      1:34
    • 17. Conditional Operations

      7:05
    • 18. Shape Manipulation

      2:34
    • 19. Array Manipulations

      3:45
    • 20. Universal functions

      1:23
    • 21. Broadcasting

      4:52
    • 22. Loading And Saving File

      1:50
    • 23. Reading And Loading Files

      2:11
    • 24. Numpy Memory Management Intro

      2:27
    • 25. Numpy Memory Management Advanced Part 1

      4:49
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

89

Students

--

Projects

About This Class

Numerical Python or Numpy is an important library when it comes to performing complex computation. In this course, we deep dive into Numpy starting with basic concepts, explaining what , why and motivations for creating such library to advanced concepts. This course can be a pathway towards becoming a data scientist.

Meet Your Teacher

Teacher Profile Image

DevTechie Interactive

Learn new everyday

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction Numpy: Hello from deft Aggie in directive. Welcome to my new cores on beginners to advanced in Mumbai. I'm very excited to present the scores to you. So without further ado, that's get started. 2. Who This Course is For: so who discourses? Far. So this course is for people who are absolute beginners who have no idea what Dona by is. And we're just starting to know what Dona by intense capabilities are and want to go a and become an expert in Mumbai. Um, there are This is also for people who can who have some knowledge about number. They have created some indie Aires I worked around their way but now want to know more deep into indexing, slicing, broadcasting and also how you can manage the memory and stuff like that. Then then also you can use the scores. So there are no protocols it for the scores. You can come to the scores. Ah, very open minded and without having any prior knowledge off by town or any of the stools, Uh, we will learn everything from scratch over here. 3. About This Course: about this course. This is a structured course that emphasizes on first building the basic concepts in Mumbai and then moving on to advanced concepts. In this, we will describe what is numb by why is it important? What are the benefits and a brief history off Mumbai Moving towards? It's the basic concept. We will spend a good chunk over time talking about nd areas, which is the building block off number. We will take a deep dive into numb by looking into indexing, slicing, broadcasting and many more. And finally, we will wrap up with advanced concepts like number, eyes, memory management. 4. Tools: so the tools that we will need for the scores. So we will use Anaconda Navigator, and in that we will be using Jupiter Notebook. So Anaconda Navigator is an open source distribution where you can write code snippets for Brighton or are, and it is supported in Lenox Windows and Mac operating system. So let's go ahead and see how we can download. Install this the stool. So open up your browser and in there you can google the World Anaconda download and you'll see that under the URL www dot anaconda dot com distribution. You so want to click on this link and over here, you we'll see the download links now, depending on what operating system you're using, it automatically detects Ah, uh, and shows you that installer. If you're in Windows, you can go to that tab and download that since I'm using Mac. So it's showing me the Americans dollar. So you go ahead and download the link suitable for year environment. I will suggest that it's better that you use part on three, because soon earthy patent do will be deprecate ID. So it's better to stick with the leaders to version, especially if you're a beginner. So all you have to do is download this link, Click on this link, and then, Ah, one stance dollars downloaded. You unzip it and just install it. So since I have already installed it, have a launch it and ah, it it'll have a whole, uh, dab there. You can see different tools that are there. So, like, there's a school, there's our studio, Uh, whichever you like, you can install it. So, for example, I have not installed me a school on our story because I don't much need it. But if you need, he needed it can be. You can install it. Um, we will be using the stupider notebook. So definitely for the score, sir installed the Jupiter notebook. Now, before even you do that, you might want to go and have a look at the environment, so it will already have a base root environment so you can go and install this in the in base root environment the year Jupiter notebook. Now, if you want to create your own environment, something, uh, and you don't want to mess up with the base root, you can you can do so. So for example, if I say test, um, it will show me the version. So let's say if I want to install 3.7 and uh oh, you're if I say test numb by now, I'm able to create my virtual environment and then it'll take a while and it will install itself. So I'm gonna boss this video until now it gets installed. So now my virtual environment is installed destined by on. And if I want ah, in here is the search box and ah, it from the drop down I can choose they installed or not installed. And if I look for numb by, I see this know nothing comes up so that means it's no installed. If I say not installed, then also it comes up. So that means I can just by the click off this bottom on da pressing apply. I can install it the other way. We can install it to buy um, opening up the terminal and the writing commands like weapon stall number. I 5. What is Numpy: So let's first address what is not. By no number, I stands for numerical by town. It is used for scientific computing and fight on. So the core off number package is not by areas also known as nd areas. Number is the most fundamental package for scientific computing in bite on, and it's the bees for many other packages. Since Python was not initially designed for numerical computing, this need has arisen in late nineties, when fighting started to become popular among engineers and programmers who needed faster vector operations. As you can see in this figure that many popular machine learning and computational packages use some of the NUM buys feature, and the most important thing is that they used numb by areas heavily in their methods, which makes numb by an essential library for scientific purposes. 6. Brief History: Let's look at the brief history of numb by. The first attempt was numeric, and it was developed in 1995 which was followed by an alternative package. Gold is no marries now. Both packages were specialized for calculations off Airy's and eat head strengths, depending on in the kicked, in which cases they were used for. That's never used differently on many circumstances. No, this ambiguity lead to an idea off unifying the two packages. So Travis, all events started to develop Denham by library for this purpose. Its first release occurred in 2000 and six. 7. Why Numpy: So let's answer the question. Why number? So when a computation must be repeated for a set of input values, it is good to represent. The data has an airy and the computation in terms of Perry operations. Computations that are formulated this way are said to be victory ized now wrecked. Arrest computing eliminates the need for many explicitly loops over the area, element by element by applying combat operations on the Harry Did So do you do this? Reason characterised. Computation can therefore be much faster than the sequence you element by element computation. No, since by Khan is an interpreted language looting over areas element by element Intel's. That's significant performance degradation. The court off Parnham by is implemented. See, so it is much more low level and provides efficient functions for manipulating and processing. Harry's now number area are homogeneous and typed. Harry. So what? What does that mean? So homogeneous means that all elements in the area have the same data type, and fixed size means that the areas cannot be resized, so not without creating a new Eri. So for these reasons, and there are many other reasons, operations and functions that are on the number area can be much more efficient and faster than those using and by Kant list 8. Concepts: in that last radio. We did talk about scale er's wrecked arised operations, and all of this can be a little confusing, especially if it's been a while for you leaving high school mathematics to understand all of this. Conceptually, let's revisit high school mathematics. You understand concept off scaler in Vector, for instance, In mathematics, Number five is a skill. Er, when we add, say, five plus three were performing and scaler tradition, leading former director out off a group of US killers. So now, in fighting programming terms, we will then have a one D area, which is 53 and four, as in this example, same concept would work for higher dimensions. So say we have two areas 53 and two elements in this area and do for and six in another area as an element in ST by Khan, we will look through each element in first area and then an atom to the corresponding element in the secondary. Now this is where bows in mathematics addition off two vectors is considered a single operation, and this is the way and numb by does it to such that these basic operations are much more efficient There are further optimization since Nam Pie is a written in low level see routines and we've uncovered not by Harry in great details. So in this example, as you can see, there is a fight on way. And there's a number way in by Conway via, ah, having to Aires a around one, any other group. And in order to add these two areas, we all you're doing is it reading through one area and then bending it? Ah, but some Ethan defending it into 1/3 eri and then to sprinting so you can deceive here and a number of areas we are all they're doing is just adding this as a number area. This is what brings the officiant seen them by 9. NDArray: said. Who? Mumbai Library is based on one main object that's in the area. A few things to note here Is there homogeneous because we're truly all elements within it out of same type and the same size and did a type off, not by areas is specified by another number. I object Caldas de Types. Kind of. The important thing about number area is that their size is fixed. That is, once you define their size at the time of creation, it remains unchanged. And this behavior is different from Bipin List. Because pipin list can grow and shrink mirrors numb by area, its size would be fixed right at the time of creation. Go ahead and create our very first Mumbai Eri so very fasting Medio is import numb by and ah, by convention it's ah uh usual practice to give it as an alias off MP and I am defining here a list as and giving a three elements inside it. And then all I do is sign of variable and do and and be dot airy and inside of this I just passed this list and let's see what this, uh shows. And that's how you greet them by area. They can check the type off. What kind off I raise this and now that's say's it's nd area. And we can also see that the data type associate it to this. So if you just do married auntie types, it shows all the elements in this, uh, in this area are in teacher. And then there are functions like NDM shape and size. So well, you have to do is specify harry dot and them and the similarly every dot shape and um known underscore they are arbiters are variable for this very that size, and that will give us the dimension shape in size. So since we have separated this by commas, it's returning. Result in a topper and it is a show so that it's a one dimensional early shape is 33 columns and one draw, and the size is there are three elements in it. Now let's see how we can create two dimensional and the areas. Then it's pretty much similar. We've used the same function and be dot harry and under the bridge brackets, uh, we put multiple list, uh, in the square brackets, so make sure that there's a square bracket and inside of that square bracket we're putting a multiple list and that these list one hour dimensions and those are the number of dimension we can provide here. And since here we here, we're giving to less. So these are two dimension that's being provided. And once he apply the same function as before, uh, with end dim shape and size and run this, we find that now the Dimension ISTEA should do because we are providing do this and similarly as before, you want to see the data types of the use uh, the function Indy types. And then, uh, you can see these are all indigenous 64 so d types isn't Let's see what happens if we change one of the characters in this dimension Dio Afghani Mary and then see what the How the r d types change for this? So now that we have changed this two x and ah, that's see how he will be, how this we'll change So that meet on this and ah, here and now The D type is uh u 21 10. Basic Operations: So far, we have seen how to create an nd eri car in the section. We'll see how to apply different mathematical operations through these areas. Okay, so first thing we do is create an A in the area, so and be dot arranger and that any number here would give me the length off that area. So if I now go and see in Irian Drum this now I see 0 to 3. So it's like a four element in this area. And now let's do some applies an operation. So just a submission. That's add five to this. This will add five to each element in the area. In a similar way. Let's do a multiplication and playing my file will give me me the mother, every element multiplied by five in the area. So now let's do something different. Let's create a new area and, uh, in this day, so let's used the same a range function, but you will be providing the reach from five tonight. So here we have our very with four elements between five and nine, and there may remember that the last element is not counted, so 5 to 9 me would mean 567 and eight. It's always length minus one. So now let's add these two areas in the other one into and now each elements get added to the subsequent element off that of the other area. So it's an element wise operation. You see air and underscore air at the very first element is zero and the end underscore er underscore to the first element is 50 plus files by and so forth in the similar way. Uh, let's do this abstraction. So let me change their syndrome this and know we see that each element is getting so abstracted and that that's resulting in minus five for the whole Larry in the Let's do the same with the multiplication and we see the similar results. And finally, let's do this for the division is well, and here are the results. Let's look at the universal functions so universal functions are again the functions that operate on an Aryan and element by element fashion. So it's again an element wise operations, And some of the examples in this, uh, in this section are like a square root log sign. So if you apply, square you to an airy than the the function is applied to each element. So in this case, let's diss create and, uh, Harry and let's bring this out. And now let's apply this square root function to this area. Uh oh. When Peter Hart Square root and then no well past this area inside of that. And now we see that function got applied toe every single element in the dairy and a similarly we can do the same for log, uh, the and be dot log and then pass on the area and similarly, the sign Go sign And there are many functions that are there that can come in very handy when you need one. So look out for these functions. Ah, there's a big documentation on that And if you need the one, ah, you can always implement it in this way. So let's move on to aggregate functions. So So aggregate functions are the functions that performing operations on the set of values so, for example, and airy, which is an nd eri and they produce a single result. So the operations like summation, um, in maximum mean and standard deviation are the ones that can be applied to such because it the operation gets a plight to the bunch of element and eventually it produces just a single element. So let's see how this works. So in our originally created area, all we do is a yard in our thought that functioning. So here are not somebody do you give me the some their daughter men and the max separated by commas that returning results in a couple eso The minimum value in this area is one and the maximum value is for and in similarly we can find out mean and the standard deviation which are really important statistical functions for statistical analysis. 11. Matrix Multiplication: it's no one to creating the Matrix product. So very fasting may do is create an in dimensional area. So we are. All we do is, um, a range in there, like media 0 to 9, and I let me reshape it to three in the three by three matrix. Since there are nine elements um, in this sir Matrix. So let's Ah, just around this and now I have three rows, three columns and the area is created. No, there are some functions, like ones and zeros in on by that begin use Teoh, create the Harris. So lets me use this MP Dr Ones. And again, let's make this as a three by three matrix. And there let's run the South. And in here we see in the three by three matrix containing on element as one. And now, if we do, um, committee cooperation with a star B, we see that it's an element wise operation. So zero times 11 times one. And that's why how we're coming with 012 exactly same? Yes, uh a That the one being for study we created. But if we want to do a matrix multiplication, we will use the start operator when we will be using a comma. Be. And here the multiplication is similar. Toe a matrix, Guard up, uh, as this. So you receive. We have two matrix A and B, and we're doing a product. So, uh, as you can see, the first row off a gets, uh, multiplied with all the elements in the very first column off B. So in here, zero gets multiplied to one. Then one gets multiplied to one, and then toe gets multiplied one. So then they all gets added together. So as you can see in this formula and this happens for each row and each column, uh, it's A and B. So now the first rule and first column of B, then for as you can see in this diagram ah, here the again For the second element where we are getting 12 the second row gets multiplied to all the elements in, uh, column one off b and ah, this happens for each, um, it'll end column. And that's how he kind of, uh, end up with this dot product 12. Increment & Decrement: so we can implement art equipment, the elements often airy by adding a number to it. That thing to note here is, though, is that render whenever we do this, are it it reassigns the value to the same area. So let's first create an area here. And ah, it's a simple area. Four elements and ah, once when we whenever we add a number, so do it. Um, the area remains same. So no copies or replica. That area is, um, is created. So let me fix this. And there. Once I do this on, let sprint it out. And so now you see that, um, one is added to each element and so this is not a copy. It's the real Larry. Now, if I d crimen a number which is one through from the same area, the values are decommitted from the latest value of theories. So in this case, 234 and five to minus one, I will be 13 minus one will be two and four minus one will be three and five minutes. Women before 13. Indexing: indexing. Slicing it. Reading is a very important concept. When it comes to nd Aires, the section will see how we can manipulate these area objects, how he can select some objects unit Using these indexes, we can assign. Different members are different elements to the elements off these areas. So let's get started. It's some hands on exercises. So first thing we know is created in the area. So via just using our own function in rage. And I am creating an airy between 10 to 16. So the values are between 10 to 16 as you can see here. No, let's understand what the indexing means with these areas. So, like, uh, this is our area with 10 from starting from 10 till 15 because that's like from then it's always and minus one. So we have all these elements here, so we have positive indexing, ending it there indexing. So if you want to select elements from the riverside off in a reviews, negative indexing and if you want to select from left right from then use positive indexing . So let's see how we can you do that. So first thing widow is our area, and we just in a square bracket, people provide the index off the elements. So in here we see three is 13. So at the position three, the values 13. So, uh, it gives us 13. No, since this also accept negative value. But negative value will only give us from the riverside off this area, that is from right side. So if I do the area off minus three and in our diagram and B c, it's again giving 13. Because even from the negative side, if we give it the numbering at minus three location, we have 30. No, let's see, if I give any off one and any off minus one, then my values are different. That is 11 and 15 and going back to our dry ground. This is and the A to the position one. We have 11 and position minus one. We have. I just Dean, if you want to select multiple elements, then we have to specify this under two square brackets and we were separated by a comma, so the position are weren't Let's say 13 and five I want to select. It will be Armagh between two square brackets, and then that's how you can specify get multiple members on. Similarly, I can get Ah, especially I can pass on negative and teachers since we're less the positive and dangers are the combination of negative and positive in danger. So in this case, I'm specifying minus one minus three in minus five. That's ah, how the former Bagram we see that's how the elements are being retrieved. Let's see how this happens in a three dimensional area. So let's create Ah, three by three matrix. So all we do is, uh can use our seem function and there give it a range. So let's do then common 19 this time and does it does nine elements and reshape it with three by three. So that way it will be three by three matrix And the let's just, uh, execute this cell and this is our the three by three matrix, uh, created. Now let's see how we can select elements from this three by three matrix. So in orderto do that as a first understand the indexing in this in this matrix. So it's s so we give the starts it with zero and goes both vertically and horizontally. Um, say if I want to select Element 12 in here. I would first give Ah, the under the square brackets specify the row and the column. So in this case, it'll be It is in the zero throw and the second column, so if I give zero comma to it will be it will be 12. So now let's say you are if you want to select a range off elements, so let's see what happens. If I specify the same only under two square brackets, then I will be able to select multiple elements. As you can see here, Uh, what gets selected is 10 11 12 16 and 17. So what you see here it's giving me the elements in Rose zero and elements in road to. So that's how 10 11 to have 16 17 and 18 of being selected. So it's again, uh, it's just giving me than a better Feroz here, and we'll see more of this than we'll elaborate on slicing 14. Slicing: so let's see what slicing is in number. So slicing is an operation which allows you to extract portions, often area to generate a new ones. One thing to note here is I can list the air is obtained by slicing our copies. Where is in numb by the areas are views into the same underlying buffer. So if you are doing slicing in a python list, that will create a new memory location. So the slice that has been created there is a number when you slice it, it is the same area. It's just pointing to the slice off. So let's see how slicing instead. So let's create an area on the user old function that is MP dot a range, Uh and ah, let me make on area between 10 to 20. So before that, let's just import the number. I instance, my Jupiter notebook has been open for quite some time. Let me just, uh, um refresh the page so that it also refreshed and ah, more you'd work says correctly. So now it's importing in Mumbai. And, uh, let me go ahead, that, uh, every and then that's do 10 to 20 and there. Let's that. Print it, print it out. Run that. Now let's see how we can do the slicing in the Serie thing to note Here is we make use of the simple colden to slice it. And here, when I write area, it has to be in a square bracket. And here I have given one golden five, which means start from the index One if you remember from our previous tutorial that the index actually starts from zero at index. So giving one would it skipped done in this example and will start from 11. And we'll go till 50 index, which will be floating in this case now. You should have remembered from the our previous tutorials that ah, the indexes from the end starts with minus one. So if I have so select from the end off this index, that is in this case, if I want to select from 19 of the last index would be minus one, and I can just go through that the same concept of indexing works and slicing. So you just have to pass those indexes and it can be given either the positive, uh, or the negative in Texas. Okay, so Now let's go ahead and and extract the airy by skipping some items. So here's how we can do it. So, uh, let's use the same area and in here were against electing the same value from 1 to 5 only we're skipping every other elements. So skip to, uh, this will give us only 11 and 13. So if we see if we just gave one and do five, you were getting 11 12 13 14. And in this, when we skip to it is skipping 12 and 14. So that's why our answer is now any off 11 and 13. Those other two elements were getting. So now let's look at some other examples. So if you want to select all the elements from beginning to and only skip the every other element, then all you can do is just separate them by colon. You do not have to write the length, so in this case you just give colon colon to, which means it'll skip every other element from that area. Conversely, if you want to specify either the beginning or the end, the last index you can do so you can specify both of them or just one off them. So in this case, we're not specifying are starting next. Only the the end index at the school and five and we'll call into would be t escape every other element. No. You can also specify something like this. Only that since it does not have any skip index items, it will just do nothing. Let's start looking at slicing in Gutierrez. So let's create an area in a similar way. That's a usar function, a range so we have a Neri on be dot a range. That's it. Make it 10 thio 19 and let's make it a three by three area. So we will be using the function our daughter reshape. So in here I put deliberately 10 20 and I'm here putting reshape best three by three and see what happens once I execute this. Because there are 10 elements, it is going to complain that the size of stent since it's a three by three, so three times three is a nine. So there can only be nine elements in this, uh, in this studio, very so he Once I fix it from 10 to 19 then we have a every not slice a Tory very be separate row and columns by comma. So in this example we have a and that this is in square brackets and first Israel comma colon. So in here the road is zero. It so the very festival and then all the columns affect all the columns. Ah, and that's why we're getting the first row and all the columns as standing in a door. Now we do similarly in direct All Rose, but only the first column again Index start from zero. So where? First column is 11 14 and 17 and that's what we're getting. So let's look a few more examples here. Little slice both rows and columns. So in this case, let's go from zero to, um, first drop, which will be zero colon toe because it's always last index minus one and four column. Let's go. Want to do so? That's just the very first called again Last index minus one. And now I assume you would know what to be would be selecting. So as you can see from the diagram, uh, rose 0 to 2, which is the zero and one, both with select dates that off then Andrew of 13 and then for the column. It's the first Columns 11 and 14 so 11 for dinner selected. So let me show you one more trick that's there. So before we were using colon to select the range of rows or columns. But if you don't want to select the Ranger arrange, we can just specify the index off the row and column. Uh, toe get that row or a column. So in this example here we saw zero comma to it in place off the road, so they have to be again separated by not separated by. But they have to be inside a square bracket, and in this example, we are selecting only the zero through and the second row, which is so you're skipping the first rule and then for the column there, selecting zero to do, which is and index last index minus one. So zero in one. So that's why we're getting 10 11 for because for the row 40 and the 16 17 for the rope second. So all you have to remember is, um, to select a range, use colon and to select specific indexes in the two D or three D areas. Use a comma. So hope you enjoyed this, Uh, slicing it is a very important and there is a very handy and often used. So with that, let's move on to our next section. 15. Iterating Array: in this lecture we will be looking at how we would be trading through an area. So we'll take our same area and we can just do a for loop into the same area and we will get in a similar way. You could get an area. So let me great this for hope and bring it out while the elements. And here are the all the elements. No, what if I don't want In this format, I wanted an element by element which is element wise. So in that even be using a function goalless flat and through that it will flatten the area and then we will be would be ableto it, rate it through. Element is how we do it If you want. We can also apply a function through this function. Golders, apply along access so you can use that and apply operations like mean some Are any other operations across thes two theories. So let's see this with an example and we will use this function called is apply along access and here we pass a the operation. In this case, let's a pasa on the mean, so we'll just use and we don't mean the numbers mean, uh and then there is Ah, Reba for X for specifying access. So access zero means column and access one means through. So in here uh, access zero means column. So now the average meanings calculated across column that means 10 plus 13 16 is the average is 13 and a similarly Viduka across row than 10 plus 11 plus 12 Bar divide by three is 11 so you can see Ah, that computes now, conversely, can also create your own function and pass that in apply along access. So this is how you can do it. You've been discreet in here. We are creating our divide by two function where we're taking the area. And if you're dividing the elements off the area by two, like so and then what? We will be doing this. We will be passing this divide by two inside off the, um, apply along access or let me copy this place this year, and instead of mp dot mean, let's up us this function divide by toe and, um, Nitze just have the access to one. And let's execute this. And now that this divide by do is you can see the elements off this area. Each element is divided by two 16. Conditional Boolean Expression: we have seen the usage offer indexing and slicing to select or extract this upset off area and alternative way to perform the selective extraction off the element in an A raise to use conditions on bullion operators. So let's see how this can be done here. I'm creating an area in our usual way using your and we don't arrange function. And once my area is created, I am looking Teoh get elements only greater than three. Let's execute this in this way I get ah, a bullion value, the true or false. But let's see if I want to get the exact value is what are the values were greater than three. I will just put that under a square bracket like so and then I get the value that whole is greater than three. Let's look at a few other examples so airy ihsaa not equal to three and again in this case , if I'm not putting it in the square backers and get true or false, putting it under a square bracket will give me the exact value. It is also possible to do an element voice comparison of two worries and to include compound expressions so in this example, received two times each element of Earth off the serious so two times for Wilton Treat eight and four plus four will also the eight, so the area off four is returned in the last example. 17. Conditional Operations: section. Let's look at a few examples off working with bullion. Airy's The first thing. First, let's create our tour the area off for three by four metrics. And in this Soviet gays, we will be using a random state function to generate the same. In the past, we have used a ridge, but this'll is a little different, so let's use that. So let's bring this out. So one thing to notice here is ah, printing this Clay returns that it's a random stayed in its surgeons. The memory address, in order to create into an area via providing toe barometers when is return, means that all the values inside of this area is under 10. So ran into his air means it's all in teachers and all indigenous are within the range 10 and then the size will be three by four. So there will be three rows and four columns. All will be having values less than 10. Now that we have our metrics less, let's perform some operation starts. Let's says some of these operations you have already seen, so let's do less than six and it gives hurt and some bullion area. Hey, who telling us Which element is true or false? Again putting this under a square bracket. Well, uh, and give me the exact values off only those that are less than six. So let's look at some other functions with Mumbai. So, uh, let's look at a counter non zero. So this function stakes the area and executes on the criteria provided. So if I say provide this area here around the school rent that we just created less than six will give me how many aggregate off harmony in the total number of elements in the Saturday that address 10 6 So the answer we get is eight. Because the first rule, all the elements are less than six I can draw to, Lindemann said less than six in the third row toward women, Celestine six, that the girls total of eight elements. Now the similar functionality. We can also get through another function. It is, ah mp dot Not some. So this function also does pretty much the similar thing s so you can use either I also some and then you provide the her the name of the area and the criteria which is less than six. And this will again give the US the, um, the value off for eight if you want to achieve a little more than just the total number of element. But you also want to get it across row or a column you can provide the access for with the same function. So in this case, if I provide access to let's say one on and so in this so it will provide me all the elements that are less than six across, uh, every jewel. So, um, in the first row, all full are less than six second row do and the third row again toe. So that's how you can do it. It's all of this is really wise. And similarly, you can want to do it across the columns. Just it. Jane Tinky Axis. You can also use the function any to see. Are there any values that asked that there are valid for a specific criteria that you have given? So in this case, if you see, uh, Harry underscore, Grant is greater than for 10. Are there any values in the industry that a greater than 10 and the answer is false? Because all the values are under 10 we rest specifically for greater than five. Miller result in a True because there are elements that are greater than five. Similarly, we can use the function. All which means are all elements are valid for a particular criteria. So in this case, are all elements in this area greater than 10. Ah, Then we get this value and then are all elements in this element in this very less than five. So we get yes, true. No, If you like, you can also provide the access averages. Acosta Ruined column as we have seen the sun, so the same would work with all and me. So this will give a car seat. Roller column Depending on the access you have specified, let's make things a little bit more interesting. So in here, the year were using the some operator, and that's used the end and are operated inside. Off this, we will need two brackets, so there's this one quotation and year providing this another condition. I'm separated by end, so both of these conditions should be accurate. Bring Severa. It's less than six, and airy is a greater than let's say for so yeah, and let's also do this across. Uh, so let's Western this And then let's do this across through our calling, losing access. So in this, you see that that yes, less than six. And they're richer than for how many elements? There's just two elements we want. Oh, do it across role color, then this. So what? So this is a cross collar. So the first column contains less than six greater than whole religious five. That's why the answer this one second and third column does not contain any such elements. And the third, um, for fourth bottom again contains thing, uh, something that is less than six and a greater than four, which is six itself. One last thing I want to show here is the use off Attila, which is used for not operation. So in this case, if you see I have a criteria where a rand is less than six and not would make negated, that would mean eight and this greater than six. So the answer was for if we do it less than equal to six, then on the answer becomes three. So if you want, you can make it a little more complex and interesting. So we have the similar criteria for the first time, and we are also using our operator. So the pipe sign means our operator and whether the first criteria or the second criteria are true, only return the count off those elements. So in this case, our answer is 11. 18. Shape Manipulation: reum already seen how we can convert a one dimensional ary into a two dimensional. Using the recent reshape Punkin in this video, we will see how we can use some other functions like a rebel. Ah, to do the same. So just as a recap, let's first generate an airy and use our reshape function to reshape it into a three by four matrix like so, if you want to modify the object by modifying the shape, you have to assign a typo containing the new dimension directly to its shape. Attribute. So in this case, we are using a dot ship and changing three by 4 to 4 by three matrix. So in this case, we have four rows and three columns are laying people having three euros and four column and make sure that it should be a murderball off to 12. So it could be six or two, um, in four or three. So those elements should be equal and come equal to the number of various that are there in a dimension. And just to clarify six and two in forward and three are in reference to this example. Now what if if you want to convert a Tory Eri into a one d eri. Now this is also possible by using revel function. So here we see our four by three Matrix is not good murdered into a one dimensional Harry. Now, another important operation is transposing a matrix, which is in wording. The columns with the rose now buy provides this feature with E a function named us transpose. Let's understand this with their originally created area A which was a three by four matrix now or did when we do use dysfunction transpose. And we see here that the, uh, the the value off pastoral second column has now switched to second row. First column. Similarly, value off first row Third column is now switched to 1st 3rd row, First column. So that's how those inversion are taking place. So I hope you find these video relevant and you saw her and see you in the next one 19. Array Manipulations: so often times we need agreed and airy, using already existing airy's. In this section, we will see how we can create new Harris by either joining or splitting the areas that are already existing. So in this regards, begin joined the areas and we can march multiple areas to form a new one that contains all off the areas. So number uses a concept off stacking so we can perform either vertical stacking our horizontal stocking. So there are many functions in this regards that are there and the vertical vertical stacking stacks in a vertical direction as opposed to horizontal stacking, which actually will generate more columns rather than rose. So let's see how this is performed. So in here I'm creating and I agree with using function once, and it's ah grating three by three matrix. This area will have all the elements as one like so let me also create another a record of zeros using the function zeros. And again, let's do this as a three by three matrix Lex Oh, and then executed. And this is a matrix. And now we're making use off the function we stock. It is vertical stack to stack these areas on top off each other's now. One thing to note here is for the stock number of columns should be seen, so three by three can stack over four by three, but three by three cannot stack over three by four. Now let's look at at Stack, which is horizontal stack and the stack one and zero And again, thing to note. Here is number of rows between the two, where he should be same for horizontal stack. It could be three by three can at stack over three by four but they cannot s at stack over four by three. So there are two more functions that perform stacking between multiple areas They are column stack and Drew stack. These are functions are different because they operate different day s comfort toe the previous V stack and it's stack. Generally, dysfunctions are used with one dimensional Larry such that these are stacked as either columns or rows in order to form a new two dimensional area. So let's start looking at the using This functions so in here I have created the 31 dimensional area. Everyone do in three, as you can see when they use just contained some values. And now let's use this a Kadhem stack to stack these Cherries in a column in a format so we will just to separate them by comma and the run this. And as you can see, all of the's are stacked ah vertically, one on top of each other. Now let's use Rose stack and narrow stack. As name suggests, Tickle stuck it in a row. Format like so, so you can see the difference between column Stack and Rose stack here with column stack 03 and six are in the first Harry, then 14 and seven. The second column is in the secondary, and to five in eight are in the third a Rivera's Inro stock. All the same areas are stack next to each other. 20. Universal functions: so universal functions are again the functions that operate on an Aryan and element by element fashion. So it's again an element wise operations. And some of the examples in this ah in this section are like a square root log sign. So if you apply square you to an airy than theme, the function is applied to each element. So in this case, let's diss create and, uh, Harry and let's bring this out. And now let's apply this square root function to this area. Uh oh. When p dot square root and then no well past this area inside of that, you know, we see that function got applied toe every single element in the dairy, and a similarly we can do the same for log ah, the and be dot log and then pass on the area. And similarly, the sign Go sign and there are many functions that are there that can come in very handy when you need one. So look out for these functions. Ah, there's a big documentation on that, and if you need one, you can always implement it in this way 21. Broadcasting: So in this section we will cover the gentle concepts off broadcasting. So one thing to remember is number. Operations are mostly the element wise, which records to Aires in an operation to have the same shape. So, for example, if you have to Aires, everyone and Sarah do. If they are same shape, we can perform any kind off operations to them. But that doesn't mean that number operations can't take two different shaped areas and ah, apply any operations to them. So number provides the flexibility to broadcast a smaller size terry across a larger one. But we cannot a broadcast to the area to just about any shape. So there are certain constraints on that, and we will cover or those rules that are required for broadcasting. So the rules around broadcasting, or to one, is all dimensions are compatible. That is, if you're performing in operations with two Aires, they should be off equal dimensions, and the second rule is one off. The dimension must be equal to one. So the key thing to remember here is broadcasting involves performing meaningful operations over to differently shaved areas, and any inappropriate broadcasting might lead to an inefficient use off memory. So let's understand the broadcasting with an example. So I have imported my library and let me create on every okay and that's printed out. So we have our first Terry. Let me create another area and now ever create Ah, one dimensional airy. And now let's upper perform an addition Operation here. So explosive y. And over here we are getting, um, the the area that is the submission off both x and y. So, as you can see, uh, this Harry gets added to this, so let's understand it further with some images. So we see here that X is a three by three matrix and why is a three by one matrix eso in numb by broadcasting the shape of why is translated to three rows now install fun. So therefore, the second condition off the broadcasting rule has met. And why is, um, broadcaster to the same shape as X by repeating it so because and now they got kind off the same dimensions ex and why? So that's how the submission is being performed. And the result we get, um, is, as you can see over here it's 11 12 13 by adding 10 Ah, do 12 and three, respectively. So now in this example, we will see how we can brought gas to both the areas. So let me create my ex again eso so again and beat out airy and like me Just get the 0 10 and 20 here and thats print out x and we already had our why So now we can see that if we do a heck start shape and why dot shape We see that excess three by one and why is has a dimension of three So when we add so as you can see this is like different dimensions on em and be add these two areas. Um, the broadcasting is happening in both x and y Among acts, it's, ah, the columns that will be broadcasted and in the way it's the Rose, as we seen in the last example that gets broadcast. Now let's, um, look at this. Understand further with the image. So he received that ex guard broadcasted in the columns and why got broadcaster than the Rose? So that's why we're getting zero plus one is one. Then 10 plus one is 11 and then 20 plus one is 21 and the similar rate to indeed plus two is 22. So so now you see that how both off the areas can be broadcasted. The only condition is that those two rules should always hold true. 22. Loading And Saving File: Hi, friends here we will look at how we can load and save data in binary files using them by. So there are two functions safe and load that helps us to save a fine and load of fire. So the very first thing we will do is in bold are a non by library. And by convention, I am giving it in L E s as and B. Now, once that's done, let me use the function a range Teoh assign a 16 element area off aid by two. So now that's done. Let's just print out this area to make sure everything's hunky dorey. So that's eight Rose. Two columns. Now let's Ah, now, this is how he saved the file. So use, uh, and P dot saver function. And this say function takes two arguments. One is the file name and the other is theater itself. So this is how we can just go and create a file. Now, let's see how we can load this file so we use numbers load function to notify on our load function only takes one argument. That's the file name, and and, uh, we need to be sure that we provide an extension because if I received a with an extension off DOT and B Y, if we fail to do so, then it will give us an error. So, uh, let's see this and then that gives us an error and it say's name Saved data is not found, eyes not defined. So you basically have to give this as a string and provide the extension for it, and then everything will work fine, like so. 23. Reading And Loading Files: Now we will see how we can read from tabular data using number using certain other functions. So to read the tabular data, we can either use lewd text function or generate from text function and see what the difference is. So I have this file in my in my machine that I'm providing a bath to. And as usual, I'm importing the library and I will use this'll or text function, and let me quickly correct the name of the function here in the comments. So, uh, dysfunction. We will provide the filing and the day limiter. So in my case, it's a comma, and a fun thing is like this. Ah, function right now, well given error. And the error is, let's see for fostering this and let's see the error and the other is that it cannot gun word string to float. And that's because the the header there is a header, and that's what it's not able to convert. So I will be using this. A skipper rules to skip the very fast rule, and you can also use if we are using going, use columns toe. Just select some of these columns, so let's see and now how this works. Fine. So now we can easily load our text. Using this method gendered from text is another method that we can use to load such files. So it is more or less like our Lord text function that it takes a violin and a dig limiter . The the major difference is that whenever it seems, sees a header. It the gun words itself on its own by putting and the value s none, not as number. So here we see Ah, that it got converted and then names equal to true would mean that, um, it's ah, if you want to the headers with it. If you just to skip this names equal to true, then all it will give is just the values. And as you can see, the top header is Ah, it's a non value because it's a header 24. Numpy Memory Management Intro: Hi there. Welcome to the new section. Offer Numb buys advanced concepts. In this section we will see how numb by manages its memory and how we can profile numbers performance. So let's get started. So once you initialize any number airy, it's a metadata and data are stored in the allocated memory. That's RAM. So, as usual, let me first to import my library on by his MP. And what I'm doing is I will create an airy here here, um, and specify certain values. Now, one thing to remember here is, um is Brighton is a dynamically deploying it, so we do not have to explicitly defined the data types. Once I give the data type, the values are dynamically inferred. So in this example, if I tried to look at the data types as Harry underscore extra data types, it should give me the flow data type like this, as we have touched upon briefly that the advantage of using number library reach other than by Tom's is that number supports many different numerical later types such as bullion end and see into B. And some of these are here. We can further see these data types by jacking SC types. Now, in order to check the barren class off any data type, we can call the Method Amaro to do this. Now, if you want to see that, it quite memory to store the data type, begin use and bites. This can be highly useful in cases when we need less position. In our calculation, we can just use and read or flu 32 which will take half off the memory that flows through Float 64 will take a look at another example. In this I have treated in Area X two from Mary X and ah, if I do converted to flow Terry, too, and look at the invites at 16 now for the same Harry X from which Harry Extra was created. If I converted to 64 the number of bytes occupied is 32 now, so we see how data types play an important role, and having a right kind of data type is a very important for a good performance and ah, memory management for Mumbai 25. Numpy Memory Management Advanced Part 1: to further profile the information and numb by the use. A library. Gold is very interface, so let me take the same airy and used this library to see more information about this area . No Harry interfaces a bike and dictionary chest. Six keys Here shape shoes. The size of the area strikes indicates a whether it is a c style a memory before. In this example, none means that it is a C style Reba for Diaper Steer has three values, first showing the by daughter. The second showing the character gold and the many character shows the number of bytes. So in this example, the greater than science F eight means that the by daughter is a little Indian. Um, character code is a floating point, and eight is the bite used, so data shows you where your data is stored. It is a Tupperware. First element shows the memory block address for the Empire Area, and the second element is a flag, which indicates whether it is a read only or not. So in this example, the first element in the step a list, a memory memory block address and the false means that it is not read only now let's see this in effect by using an example. So over here I have an airy and India area. It is important to know that when we create an anti area based on an existing area by slicing, it made a great the performance. So let's see this in this example. So we're creating a three dimensional area and we can slice it. Created another every. So here's what will happen when slicing and slicing the Serie First all items from the first dimension will be selected. Then every second I item from the second dimension will be selected. And then every third item from the third dimension will be selected first. Understand? This is how the system So ah, as we see here the first this is a result. Um, all the elements from the first dimension is selected, so that means we have, like, four dimensions here. The very first dimension has ordered for, uh, elements. 12 34 So that's why we are getting for bigger. All the elements from the very first image sensor are selected. No, um, from the second dimension, every second element is selected. So second dimension would be your insight. So only the 2nd 1 to three. So every second So this one will be selected. Then this one will will be selected. It'll skip one and then this one will be selected. So that's why our results show 10.66 in here. Line 66 and then if you will see, this will be skipped. And then the first element off here will be selected 1.355 and then, ah, this will be skipped. And then we will get 0.53373 in the very 1st 1 and then the third element from the third is selected. So once this is selected, then the third would be or are you skip toe 12 and then this one. So 2.6 So that's why we're seeing once this is selected to point or six is selected. Then again, Skip, do this one, This one and then you get born 3959 and then you get point a 59 So I don't see what area androphy instances about both of these areas, the one that's original and the one that's created by slicing. So now that we have seen how these areas get created. That's doesn't let's see her. What's the memory address of the estuary? So originally our area was Indy everyone and be created and the Alito from Andy. Everyone. So that's Ah, around this. So now that the me see they have Andy everyone, now that it's giving us the miss it you see that the for the nd everyone Streit's Arman Minnis Straits has is 96,000 and 1 60 for India to because off this whole slicing. So So we see how how slicing can be taxing.