此函数在数组上返回一维迭代器,它的行为类似于Python的内置迭代器。

import numpy as np 
a=np.arange(8).reshape(2,4) 
print 'The original array:' 
print a 
print '\n' 

print 'After applying the flat function:' 
# returns element corresponding to index in flattened array 
print a.flat[5]

其输出如下-

The original array:
[[0 1 2 3]
 [4 5 6 7]]

After applying the flat function:
5

参考链接

https://www.learnfk.com/numpy/numpy-ndarray-flat.html