Descargar el Código: patreon.com/pythonmaraton
Join Patreon: patreon.com/pythonmaraton
^Downloadable code & more! This video walks through array indexing examples. Array[rowstart:rowend, columnstart:columnend] It also shows how to get the diagonal using np.diag().
This is a Python anaconda tutorial for help with coding, programming, or computer science. These are short python videos dedicated to troubleshooting python problems and learning Python syntax. For more videos see Python Help playlist by Rylan Fowers.
✅Subscribe: / @pythonmaraton
📺Channel: / @pythonmaraton
▶️Watch Latest Python Content: • Python String Slice and List Slice
▶️Watch Latest Other Content: • Video
ARRAY INDEXING
Array indexing is very important to know. I will introduce it here.
We import numpy as np, since we will be creating arrays
For this example I will make a random matrix A with numbers between -5, and 5.we don’t need to import random. We will make it (3,3)
And we will change it to ints really quick
So here is A
Let’s bring it up again so we can have it for reference.
First if you want any entry in the array simply type its corresponding row and column index location with a comma separating.
Don’t forget that when coding, the first number is always 0.
So we follow row position 2, and column position 1 which gives us our -1
Now we type 1 colon. This starts from the 1 position row, and the colon tells it to go to the end. So this will be the 1 position row to the last position row.
Let’s compare this to colon 1. This does all the rows up to but not including the row in position one. So it will just print out the row in position 0.
Next let’s bring up A again for reference
1 colon, comma 1. After the comma it references columns. So this is the 1 position row to the end towards the bottom and taken specifically from the 1 position column
Next we have 1 comma 1 colon. This will be the row in the second position, and then the column from the first position to the end.
Now, we do 0 colon comma 1 colon 2. This will take the row in the 0th position to the end, but limit it to only the row in column position 1 up to but not including column position 2.
So that will give the middle column, as we see here.
Something good to remember for this video when indexing arrays is that rows (or the first numbers in the index) move you up and down and columns (the second numbers in the index) move you left and right
lastly I will quickly show you an easy way to get the diagonal of the matrix.
np.diag(A) will return an array with the diagonal
You can change the index with a keyword argument if you want above or below.
For here we have one above
Now we will do a negative to go below the diagonal.
There you have it, that is an introduction of python numpy array indexing
#PythonMarathon #LearnPython #PythonTutorial
Auf dieser Seite können Sie das Online-Video Numpy Array Slicing Tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Python Marathon 20 August 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,802 Mal angesehen und es wurde von 21 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!