
上QQ阅读APP看书,第一时间看更新
3-5-2 多维数组的索引
下图是二维数组内容与相对位置的索引图。

要索引二维数组内容须使用2个索引,分别是axis=0的索引编号与axis=1的索引编号,细节可以参考下列实例。
程序实例ch3_13.py:列出二维数组特定索引的数组元素。

执行结果

注:上述第8行“x4[2][1]”,也可以写成“x4[2,1]”,读者可以参考ch3_13_1.py,代码如下所示。

下图是三维数组内容与相对位置的索引图。

要索引三维数组内容须使用3个索引,分别是axis=0的索引编号、axis=1的索引编号与axis=2的索引编号,细节可以参考下列实例。
程序实例ch3_14.py:列出三维数组特定索引的数组元素。

执行结果

上述第9行索引的引用方式也可以参考ch3_14_1.py实例,代码如下所示。
