MCPcopy Create free account
hub / github.com/numpy/numpy / MaskedIterator

Class MaskedIterator

numpy/ma/core.py:2589–2694  ·  view source on GitHub ↗

Flat iterator object to iterate over masked arrays. A `MaskedIterator` iterator is returned by ``x.flat`` for any masked 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 C-contig

Source from the content-addressed store, hash-verified

2587
2588
2589class MaskedIterator:
2590 """
2591 Flat iterator object to iterate over masked arrays.
2592
2593 A `MaskedIterator` iterator is returned by ``x.flat`` for any masked array
2594 `x`. It allows iterating over the array as if it were a 1-D array,
2595 either in a for-loop or by calling its `next` method.
2596
2597 Iteration is done in C-contiguous style, with the last index varying the
2598 fastest. The iterator can also be indexed using basic slicing or
2599 advanced indexing.
2600
2601 See Also
2602 --------
2603 MaskedArray.flat : Return a flat iterator over an array.
2604 MaskedArray.flatten : Returns a flattened copy of an array.
2605
2606 Notes
2607 -----
2608 `MaskedIterator` is not exported by the `ma` module. Instead of
2609 instantiating a `MaskedIterator` directly, use `MaskedArray.flat`.
2610
2611 Examples
2612 --------
2613 >>> x = np.ma.array(arange(6).reshape(2, 3))
2614 >>> fl = x.flat
2615 >>> type(fl)
2616 <class 'numpy.ma.core.MaskedIterator'>
2617 >>> for item in fl:
2618 ... print(item)
2619 ...
2620 0
2621 1
2622 2
2623 3
2624 4
2625 5
2626
2627 Extracting more than a single element b indexing the `MaskedIterator`
2628 returns a masked array:
2629
2630 >>> fl[2:4]
2631 masked_array(data = [2 3],
2632 mask = False,
2633 fill_value = 999999)
2634
2635 """
2636
2637 def __init__(self, ma):
2638 self.ma = ma
2639 self.dataiter = ma._data.flat
2640
2641 if ma._mask is nomask:
2642 self.maskiter = None
2643 else:
2644 self.maskiter = ma._mask.flat
2645
2646 def __iter__(self):

Callers 1

flatMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected