Numpy - 2d array indexing

According to docs numpy, the default is to index arrays first by row, and by column:

a = numpy.arange(6).reshape(3,2)

[[0 1]
 [2 3]
 [4 5]]

print a[0][1] # is 1

I want to index an array using a geometrically oriented legend a[x][y], both in the x and y axis. How to change the indexing order without changing the shape of the array to a[0][1]return 2?

+5
source share
1 answer

You can write a.T[0,1]to use array transpose indices, which are other ways in 2D.

+8
source

All Articles