classnumpy.flatiter
Flat iterator object to iterate over arrays.
A
iterator is returned by x.flat for any array x. It allows iterating over the array as if it were a 1-D array, either in a for-loop or by calling its next method.
Iteration is done in row-major, C-style order (the last index varying the fastest). The iterator can also be indexed using basic slicing or advanced indexing.
Attributes:
A reference to the array that is iterated over.
An N-dimensional tuple of current coordinates.
Current flat index into the array.
Methods
Notes
A
iterator can not be constructed directly from Python code by calling the
constructor.
Examples
>>> importnumpyasnp>>> x=np.arange(6).reshape(2,3)>>> fl=x.flat>>> type(fl)<class 'numpy.flatiter'>>>> foriteminfl:... print(item)...012345>>> fl[2:4]array([2, 3])