本篇博客主要介绍如何遍历numpy数组。
下面是示例代码:
import numpy as np
num = np.zeros([2, 3])
[rows, cols] = num.shape
print(rows, cols)
for i in range(rows):
for j in range(cols):
print(num[i, j])
运行结果:
2 3
0.0
0.0
0.0
0.0
0.0
0.0
欢迎关注我的公众号:
编程技术与生活(ID:hw_cchang)