armandino
armandino

Reputation: 18582

numpy - 2d array indexing

According to docs numpy's default behaviour is to index arrays first by rows then by columns:

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

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

print a[0][1] # is 1

I want to index the array using the geometrically oriented-convention a[x][y], as in x-axis and y-axis. How can I change the indexing order without modifying the array's shape so that a[0][1] would return 2?

Upvotes: 5

Views: 6467

Answers (1)

Jon
Jon

Reputation: 889

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

Upvotes: 8

Related Questions