简体   繁体   中英

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?

您可以编写aT[0,1]来使用数组转置的索引,这在2D中是相反的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM