So we've been through a hell of a lot so far we've looked at creating arrays we've looked at viewing
arrays we've looked at manipulating and comparing arrays.
Now number five which is if you have an array of numbers sometimes you might need to sort them.
So we'll go sorting arrays make a nice little heading here.
Beautiful so let's have a look.
We've still got random array somewhere we created this.
Okay wonderful.
Now if you wanted to recreate this how would we do that.
So let's go Eagles and at random.
Now this is full of integers so we want Rand int and we want up to 10 and we'll give it a size of how
many.
What's the shape of random array.
I believe we could tell this by just counting the horizon three by five.
Let's say three by five.
Wonderful.
Three five.
So we just recreate that if you don't have it.
Otherwise you can tissues the one that saved in memory.
We recreate it for completeness.
Wonderful.
Rain rain not shape.
There we go.
So now what if we wanted to sort the numbers in this array well none Pi has a function called MP dot
sort.
We're going to check the shift tab to see what it does return a sorted copy of an array.
This is a zero.
Wonderful.
So if we pass random array in there what is it going to do.
It's going to sort the numbers on each axis.
So if we see this first one here and this first array one is now on the very left five comes after that
because it's the second highest then seven then eight nine wonderful.
So now let's keep going.
Number five also has a method called ARG sort and we're going to see what this says returns the indices
that would sort an array.
So sometimes you might not want to sort the values instead you want to figure out which index has the
highest value.
So let's do that.
We'll pass it random array.
Wonderful getting a bit confusing here having all these different arrays.
We'll see random array again.
So we've got random array here we're calling ARG sought on it.
So this is going to sort the indexes.
So one is a lower set score the 0 number Yep then 5 is got one.
Yep.
And then seven has got two wonderful okay.
So this is sorting the indexes for us and telling us what order they would come in.
So let's see our trusty array a one we'll see another example of that MP dot arg.
Nice and simple so you can see this is already in order if we use args saw.
Okay.
So this is the order that the indexes would come in 0 1 to make sense.
What if we wanted to find the minimum number where the index where the minimum number comes from.
We can do.
I mean a 1 is 0.
So the minimum value in a 1 min the index it appears at is 0.
We could do the same with Max where we want the max value of a 1 2.
What if we did OK Max on our random array review our random array again Max random right.
We want to know where the maximum number occurs in one of these array.
So let's see what happens.
Let's do a shift tab first actually returns the indices of the maximum values along an axis.
OK for what.
Axis is that on Well that doesn't really help us.
Let's go.
Access equals zero.
There we go so this is going to give us the maximum values along access equals zero.
So this is 1 1 1 so index 1 has the maximum value I think access 0 is going to be for the rose.
Let's figure this out together.
Arg Max see this is where I get confused as well looking at different arrays and trying to sort them
out.
Axis is what happens here for 1 1.
OK so this is going in the columns I believe.
So this is where we're getting confused.
So we have here it says position 4.
This is the highest number yet.
So access 0.
Now we go on position 1.
We have number nine here.
Yeah in the row three the highest is 1 here.
So 5 is in that so then on the flip side we just went down vertically.
Now if we go down horizontally which is what axis zero is across here we have one is the highest and
we're looking at these three numbers.
So yeah.
Position 1.
Yeah.
Then we have one again.
So 0 1 2.
Yeah.
That's position 1 there.
And if we go here we have the max is 4.
Ah ha 0.
Yep 0 so that's where it takes a little bit of practice of just typing out commands like this and viewing
them and then working it out for yourself.
I've been doing this for a while now and I still get confused with different accesses of none by race
so don't fret if you're having trouble going ah which axis is this related to which is that sometimes
viewing arrays like this gets a bit confusing until you actually type out a command and then go retrace
the steps back through So what else do we have.
Well I think that yeah that'll probably sum it up for sorting arrays.
Now the beautiful thing about num pi is that all of these functions you've seen can be used across any
and array so don't worry if it all seems overwhelming that we've been through in terms of manipulating
comparing arrays sorting arrays have a play around create some of your own arrays and manipulate them
try to sort them try to do dot products on them and whatnot.
I learn the most when I just try to make some things out of numbers and a practical example really helps.
So before we wrap up the umpire section let's have a look at a practical example.