I'm learning some basic of indexing in numpy. I don't understand why
a = np.array([[1,2], [3,4], [5,6]])
b = a[[1,2]]
pprint(b)
gives
[[3 4]
[5 6]]
a[[1, 2]] specifies to return the second (index 1) and third (index 2) rows of the array.
[1, 2] is the indexer. If you wanted to get the first (index 0) column of the array, you would use a similar indexer, only passing it to the second position:
>>> a[:, [0]]
array([[1],
[3],
[5]])
The : basically means "just select all the rows", and [0] means "select the 0th column".
a[[1,2]] implicitly mean a[[1,2], :]?a[[1,2]] actually means a[[1,2], :] (without the FutureWarning: ..., since 1d). And both indexes of a[[1,2],0], a[[1,2],1] got broadcast into shape (2,), and then the results stack along the second-axis(i.e. the number of columns increases).
a[2,1]is an element, because it indexes both rows and columns. It can also be written asa[(2,1)]. Here the distinction between list and tuple is important.