-
class numpy.flatiter
[source] -
Flat iterator object to iterate over arrays.
A
flatiter
iterator is returned byx.flat
for any arrayx
. It allows iterating over the array as if it were a 1-D array, either in a for-loop or by calling itsnext
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.
See also
-
ndarray.flat
- Return a flat iterator over an array.
-
ndarray.flatten
- Returns a flattened copy of an array.
Notes
A
flatiter
iterator can not be constructed directly from Python code by calling theflatiter
constructor.Examples
12345678910111213>>> x
=
np.arange(
6
).reshape(
2
,
3
)
>>> fl
=
x.flat
>>>
type
(fl)
<
type
'numpy.flatiter'
>
>>>
for
item
in
fl:
...
print
(item)
...
0
1
2
3
4
5
12>>> fl[
2
:
4
]
array([
2
,
3
])
Attributes
coords
An N-dimensional tuple of current coordinates. Methods
copy
()Get a copy of the iterator as a 1-D array. next
x.next() -> the next value, or raise StopIteration -
numpy.flatiter

2025-01-10 15:47:30
Please login to continue.