‫So we've been through a hell of a lot so far.
‫We've looked at creating a raise.
‫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 go sorting arrays, make a nice little heading here.
‫Beautiful.
‫So let's have a look.
‫Have we still got a random array somewhere?
‫We created this.
‫Okay, wonderful.
‫Now, if you wanted to recreate this, how would we do that?
‫So let's go equals np random.
‫Now this is full of integers so we want rand int and we want up to ten 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 rows.
‫Three by five.
‫So let's see.
‫Three by five.
‫Wonderful.
‫Three, five.
‫So we're just recreate that.
‫If you don't have it.
‫Otherwise, you can just use the one that's saved in memory.
‫We recreate it for completeness.
‫Wonderful.
‫Ran right on shape.
‫There we go.
‫So now what if we wanted to sort the numbers in this array?
‫Well, num pi has a function called NP sort.
‫We're going to check shift tab to see what it does.
‫Return a sorted copy of an array.
‫And this is a Z array.
‫Wonderful.
‫So if we pass random array in there, what's it going to do?
‫It's going to sort the numbers on each axis.
‫So if we see this first one here, this first array.
‫One is now on the very left.
‫Five comes after that because it's the second highest.
‫Then seven, then eight and nine.
‫Wonderful.
‫So now let's keep going.
‫NumPy also has a method called arg.
‫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 one to false.
‫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 sort on it.
‫So this is going to sort the indexes.
‫So one is a lower says this is zero number.
‫Yep.
‫Then five has 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 npr.org sort.
‫Nice and simple.
‫So you can see this is already in auto if we use ag sort.
‫Okay.
‫So this is the order that the indexes would come in zero one to make sense.
‫What if we wanted to find the minimum number where the index where the minimum number comes from, we
‫can do ag min a one is zero.
‫So the minimum value in a one arg min, the index it appears at is zero.
‫We can do the same with arg max when we want the max value of a one.
‫Two.
‫What if we did our max on our random array?
‫Review our random ray again.
‫Max random, right.
‫We want to know where the maximum number occurs in one of these arrays.
‫So let's see what happens.
‫Let's do a shift tab first.
‫Actually returns the indices of the maximum values along an axis.
‫Okay.
‫Four.
‫Hmm.
‫What axis is that on?
‫Well, that doesn't really help us.
‫Let's go.
‫Axis equals zero.
‫Oh, there we go.
‫So this is going to give us the maximum values along axis equals zero.
‫So this is 111.
‫So index one has the maximum value.
‫I think axis zero is going to be for the rows.
‫Let's figure this out together.
‫ARG, max, this is where I get confused as well.
‫Looking at different arrays and trying to sort them out accesses what happens here for one one.
‫Okay, so this is going in the columns, I believe.
‫So this is where we're getting confused.
‫So we have here.
‫This is position four.
‫This is the highest number.
‫Yeah.
‫So axis zero.
‫Then we go on position one.
‫We have.
‫Number nine here.
‫Yeah.
‫In the row three.
‫The highest is one here.
‫So five is in that.
‫So then on the flip side, we just went down vertically.
‫Now if we go down horizontally.
‫Which is what Access Zero is.
‫Across here we have one is the highest and we're looking at these three numbers.
‫So yep, position one.
‫Yep.
‫Then we have one again.
‫So 012.
‫Yeah, that's position one there then if we go here.
‫We have the maxes for zero.
‫Yeah, zero.
‫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 an umpire race.
‫So don't fret if you're having trouble going oh 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 will probably sum it up for sorting arrays.
‫Now, the beautiful thing about NumPy is that all of these functions you've seen can be used to cross
‫any era.
‫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'll own 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 numpy section, let's have a look at a practical example.