Subtitles section Play video Print subtitles Oh, right now that we know how to create and name a matrix, let's Lauren how to subset and select single and multiple values from it. Remember what we said about matrices? They are natural extensions to Victor's. Well, it's upsetting. Matrices works in much the same way Indexing and slicing happens with Victor's. We just need to take into account that matrices have two dimensions instead of one. Okay, let's get to it. I will create a matrix very, very quickly. This matrix gives us the box office grosses of 08 Harry Potter movies on U. S soil and worldwide. I have intentionally left the column and row names blank. We will have no difficulty adding them later. Okay, take a look at the matrix we just made. It has eight rows into columns, and our index system, according Rose are indexed with the number of the row, followed by comma in square brackets. Where's columns are index back comma, followed by the column number again in square brackets. So why is that? Well, this is the way ours notation system is all set up. Extracting a value happens with for brackets and the values you want extracted in those square brackets. If you're working with fluoride dimensional objects, think of ours extraction schema as looking like this. Basically, the element that's always there is the coma. Okay, let's try and call a single value from the Matrix 897. It is located on the sixth row end in the second comb and just like indexing Victor's Weaken type, HP met open square bracket, roll number, comma column number closes, crib rackets and we get the value we wanted. 897. Great, easy. What if I wanted to Cohen. Entire row. However, with all the values in that role, let's say I want to get the U. S. And worldwide box office figures for the movie on the sixth row. If I just type this our returns 290 a single value, What does that happen? Well, here is why, when we give our this specific instruction, it looks for the sixth value, not the role, not the column. So R goes through all the values in the Matrix one by one. Call him by column left to right, and it counts. 290 is the sixth value So this is what is returned if we really want to get the entire six role. I should have typed the comma after the row number and used the blank space to indicate that I want every value on that rope. Open bracket six comma blank space, Close brackets. This returns 298 197 all the values in the sixth row. The exact same logic applies to extracting an entire column, but this time the coma precedes the column index. So H p matt square brackets blank space comma to close the square brackets and viola all eight values. For the second column, notice that our returns the result as a vector instead of a matrix. This is because we're only asking for a one dimensional object, and a vector suffices to store such information. Which brings me to the next type of subsiding selecting multiple elements. This and more ruby the topic of the next lesson form or videos like this one.

B2 matrix column comma sixth square blank Data Science & Statistics: Indexing an element from a matrix 12 0 林宜悉 posted on 2020/03/10 More Share Save Report Video vocabulary