Proceeding by steps:
import numpy as np
a = np.array([[0,1,2],[3,4,5],[6,7,8],[9,10,11]])
print(a)
gives 2d array a
:
array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11]])
Then:
row = np.array([[0,0],[3,3]])
assigns to 2d array row
values [0,0]
and [3,3]
:
array([[0, 0],
[3, 3]])
Then:
col = np.array([[0,2],[0,2]])
assigns to 2d array col
values [0,2]
and [0,2]
:
array([[0, 2],
[0, 2]])
Finally:
b = a[row,col]
assigns to b
values given by a[0,0]
, a[0,2]
for the first row, a[3,0]
, a[3,2]
for the second row, that is:
array([[ 0, 2],
[ 9, 11]])
Where does b[0,0]
<-- a[0,0]
come from? It comes from the combination of row[0,0]
which is 0 and col[0,0]
which is 0.
What about b[0,1]
<-- a[0,2]
? It comes from the combination of row[0,1]
which is 0 and col[0,1]
which is 2.
And so forth.