简体   繁体   English

numpy - 二维数组索引

[英]numpy - 2d array indexing

According to docs numpy's default behaviour is to index arrays first by rows then by columns: 根据文档, numpy的默认行为是先按行然后按列索引数组:

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. 我想使用几何定向约定a[x][y]索引数组,如x轴和y轴。 How can I change the indexing order without modifying the array's shape so that a[0][1] would return 2? 如何在不修改数组形状的情况下更改索引顺序,以便a[0][1]返回2?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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