使用 flat 属性 返回 numpy.flatiter对象(唯一获取flatiter的方式)
a = np.arange(4).reshape(2,2)
print(a)
f = a.flat
print(f)
for item in f:
print(item)
# 输出结果
[[0 1]
[2 3]]
<numpy.flatiter object at 0x10082c000>
0
1
2
3
a = np.arange(4).reshape(2,2)
print(a)
f = a.flat
print(f)
for item in f:
print(item)
# 输出结果
[[0 1]
[2 3]]
<numpy.flatiter object at 0x10082c000>
0
1
2
3
本文标题:Numpy 数组的遍历
本文链接:https://www.haomeiwen.com/subject/kohxjxtx.html
网友评论