python 二维数组遍历
时间: 2023-11-28 12:45:05 浏览: 91
2dloop2darray_pl.7z
以下是两种Python遍历二维数组的方法:
1. 使用嵌套循环遍历二维数组
```python
world = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
for i in range(len(world)):
for j in range(len(world[i])):
print(world[i][j])
```
2. 使用numpy库遍历二维数组
```python
import numpy as np
world = np.zeros([3, 3])
for i in range(world.shape[0]):
for j in range(world.shape[1]):
print(world[i][j])
```
阅读全文