All right now we've had a little bit of a conceptual overview of num pie.
Let's get hands on and start to write some num pi code.
So I'm going to follow the little workflow that we've we've kind of set up over the past few lessons
and sections start off in a terminal.
And I'm going to change directory into this little folder that I've got on my desktop.
Yours may be stored somewhere else to see the slash airmail course.
Now I've got a folder in here called sample project which has my environment.
You'll want to change into the same folder that contains your environment.
Hit enter.
Now nowhere in the sample project folder.
Beautiful.
And we're going to check using Condit end list where our environments are so I can say I've got one
here I've got a few currently.
Base is activated because got the star but I want this one because that's in my sample project folder
so I'm going to type it out.
You could copy this and do Conda activate this here but where in the practice of writing things for
ourselves because I want to get as used to as possible writing as much code as possible email cause
sample project.
Now remember you'll want to change yours to wherever your environment folder is stored activate the
first thing we notice is that this has changed from base to our active environment now and next step
is to create a Jupiter notebook our favorite workspace tool let's load that up now listen open our browser
we brought to the Jupiter dashboard it's nice and zoomed in excellent we've got our folders here and
files that are within our sample project folder.
Yours may be a little bit different but we can see in my case about the introduction to Panda's notebook
the example notebook from before my environment folder we're not worried about these we're going to
start a new notebook Python 3 first thing we're gonna do is rename it to introduction to num PI because
that's what we're working on.
Hit enter and we'll save that when we come back to the dashboard we've now got introduction to num pi
running beautiful.
Now the first step for using num pi is to import it import num pi as an P MP is just short for num pi
if you see this abbreviation somewhere you can probably safely assume that it's referring to num pi
it's just to prevent us from having to type out num pi every single time we want to use a command we'll
hit shift and enter beautiful now in this section and we're going to be focused on num PIs data type
and attributes so that's all we'll create a little heading because we are in the business of making
attractive and communicate of notebooks data types and attributes will escape and M to turn it into
a markdown cell wonderful data types and attributes.
Now data types as a plural is kind of a lie because none pi main data type is indeed array it's only
really got one day at a time so everything you see in num pi is likely an NDA array and this stands
for n dimensional array and an array can be almost any list of numbers you can imagine an n dimensions
means or the list of numbers could be almost any shape that you can imagine but rather than talk about
it let's create it so A1 for array one will create a sample array now you can do that by going num pi
dot array which just means access the array function from num Pi which we've imported as MP and to build
an array which is a list of numbers we want to pass at a list of numbers so let's do that and then to
see it we'll type it again shift and enter Excellent.
We've got our first name pie right now this is exciting.
Let's check the top of it nun pie DOT and the array.
Wonderful.
So that's the same as here.
Remember this is just n dimensional array.
Now for some more examples let's create a few more arrays empty array or type out this one.
This will have two brackets.
We'll see why in a second.
Now we'll separate it.
We'll go to another line.
One two three four five actually.
Let's make this six point five.
And this three point three.
So we've got some floats as well as integers inside num pi.
There we go we might make another one called a three empty array and this one we might actually do three
brackets.
So we're getting a bit adventurous here.
We'll make this one two three.
Let's go all the way up to 18.
Bear with me type along if you can.
Five six and then we'll go seven eight.
Want to make sure it looks all right.
Nine and then leave two brackets here.
Oh actually yeah.
Two brackets.
That's correct.
I'm just counting the number of brackets you'll see why this is important in a moment which is typing
out the numbers from one to 18 in a very kind of cryptic format at the moment 13 14 15.
Got a little bit more 16 17 18.
My goodness we made it in the end.
Let's see if this cell runs.
Beautiful.
If in doubt run the code now why would we do that.
Well let's have a look at these two arrays.
A two there we go we can see that we've got two sets of brackets here.
You got two more here.
Now let's have a look at a three.
OK.
Now this one it's kind of come out the exact same way as we've got here.
Mm hmm.
Now before we get any further and check out some of the attributes that these arrays have built in let's
have a look at the anatomy of an array.
So this is the anatomy of a name pi array.
This is a one the one that we've just created.
This is a two.
And this is a three as a reason why I put in these numbers here.
So we can exemplify the kinds of shapes of different arrays.
Now this is very important in machine learning because oftentimes with a machine learning algorithm
your main focus will be making sure the shape of your data that goes into a machine learning algorithm
lines up with the other data that you're putting in as well as the output.
But we'll see that in future sections.
This is just learning the shape of different num pi arrays.
So I've got one here.
There's one row and three columns.
So this would be shape 1 3.
Now this kind of data here is referred to as an array or vector a vector is just a one dimensional array.
If we go to this next one which is A2 we've got two rows and three columns.
So this one has the shape to three it's more than one dimension and can be referred to as a matrix.
So if you hear something referred to as a matrix it's probably got more than one dimension.
So see how a vector vectors just one row.
This matrix has two rows.
And if we go down to a three we're starting to get three dimensional here because we've got got the
access going back here.
This is where the N N N dimensional array comes from.
That's very hard for us humans to visualize anything more than three dimensions.
But in num pi and with computers you could have as many ends as you want.
So this could go up to four to five up to six up to seven depending on what type of data are working
with.
You may have thousands of different dimensions but if you hear axis zero it's usually referring to rows.
Axis one is usually referring to columns and then access n is usually referring to dimensions that are
beyond just rows and columns.
So this array here or A3 would have the shape to three three because there's two rows three columns
and we've got three across here.
So that's the final one here.
And now if n was higher there might be more commas and this little shape would extend out here.
Okay.
So now we've got the anatomy of a no higher rate down pat.
Don't worry you can take a screenshot of this if you like.
Otherwise it'll be in the resources section.
Let's have a look at some of the attributes associated with no higher res.
So the first one we'll take a look at is a one dot shape so it's three comma something.
Now this is blank.
Now the way num pi kind of format this data is that although we've said that the shape is 1 3 num pi
kind of stores it without the row at all.
So it's just got the three numbers here.
That's just a little tidbit of how num pi displays some kind of shapes.
But if we have a look at the shape of A2 we can see that it's the same as what we've used in our anatomy
of a known pi array.
Then if we go the same for a 3 2 3 3 OK let's have a look at a few more.
So if we are a one and dim which is short for number of dimensions maybe we do a two dot end them and
a three them.
And what putting the comma here will do is when the code comes out it'll just print it with commas spacing
that three different variables apart.
So this is number of dimensions.
So A1 let's have a look at it again.
One has a dimension of 1.
We'll have a look at A2 as a dimension of 2 and A3 has three dimensions.
And so this is where the MDMA data type comes in is that these dimensions depending on how complex your
data is could just keep going.
And now the whole premise here is we'll see some practical examples in the next couple of videos is
that whatever data you're working with it somehow gets turned into numbers and then a machine learning
algorithm will find patterns in these numbers.
Now depending on what data you're working with will depend on how many dimensions Zehra.
But let's not stop there.
Let's have a look at the D type attribute.
You might be able to guess what data type these are.
Let's go here shift into so we can see in our A1 array we've got ints in our A2 we've got floats as
well as int.
But it's going to default to float because that can only be one kind of data type so it will automatically
just turn the rest of the numbers in here into floats and A3 is also just integers we've got a couple
more.
A one size a two size a three size we've got three elements in a one we've got six elements in a two
and we've got 18 elements in a three.
If we have a look at a three that makes sense beautiful so the size attribute tells us how many elements
we've got total in our right now.
One last one which is type 2 type 2 type a 3.
I think we've already seen this but I'm going to get you to guess what it is before we hit shift and
into 3 2 1 these are all in the array.
So although they vary in size and shape a A1 a two and a three are all of the type NDA right now this
is an important concept to remember.
No matter what type or what shape your number higher rate is all of the functions and different data
manipulations that you see throughout this section.
If it's in an umpire.
If your data is in a m the array data type all of the things were about to go through can be used on
that.
So that's a very important point to remember is that the NDA Ray is a universal data type and it's very
very flexible to now to really exemplify num pi being the backbone of other scientific data packages
that is let's put a note here.
Create a data frame from num pi array.
So let's have a look first will import panders as PD beautiful and then we might create one from our
existing array.
So the data frame we're just gonna pass at A2.
Let's have a quick look at what A2 is a A2 wonderful.
So there's A2.
Now let's see what that looks like.
You need to view it shift and enter.
There we go.
So this is a panda's data frame and this is our num pi array.
So essentially no matter what's in our Panda's data frame if it's all numbers and panders is built on
top of num pie so to represent our data as a data frame it's just combining num higher res in a formatted
way.
So that's a very important point to remember as well is that once we start to get into the weeds of
num pie and start to work out what kind of numerical computing it can do we can start to think okay.
So if we have some data and we imported and panders it's actually just a different combination.
Umpire res so if we want to perform some manipulations on it we're actually just performing manipulations
on different lists of numbers horror as a brief introduction to num plays main data type.
That's the main thing to take away from this is that NDA array whatever array you have in num pi is
of type in the array and that panders and other machine learning algorithm packages are built on top
of num pie and machine learning is finding patterns in num pi arrays.
So with that being said let's take a little break if you need to go back and explore create an array
of your own by trialling it out.
If in doubt run the code and I'll see in the next video.