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
| 2658 | |
| 2659 | |
| 2660 | class MaskedIterator: |
| 2661 | """ |
| 2662 | Flat iterator object to iterate over masked arrays. |
| 2663 | |
| 2664 | A `MaskedIterator` iterator is returned by ``x.flat`` for any masked array |
| 2665 | `x`. It allows iterating over the array as if it were a 1-D array, |
| 2666 | either in a for-loop or by calling its `next` method. |
| 2667 | |
| 2668 | Iteration is done in C-contiguous style, with the last index varying the |
| 2669 | fastest. The iterator can also be indexed using basic slicing or |
| 2670 | advanced indexing. |
| 2671 | |
| 2672 | See Also |
| 2673 | -------- |
| 2674 | MaskedArray.flat : Return a flat iterator over an array. |
| 2675 | MaskedArray.flatten : Returns a flattened copy of an array. |
| 2676 | |
| 2677 | Notes |
| 2678 | ----- |
| 2679 | `MaskedIterator` is not exported by the `ma` module. Instead of |
| 2680 | instantiating a `MaskedIterator` directly, use `MaskedArray.flat`. |
| 2681 | |
| 2682 | Examples |
| 2683 | -------- |
| 2684 | >>> import numpy as np |
| 2685 | >>> x = np.ma.array(arange(6).reshape(2, 3)) |
| 2686 | >>> fl = x.flat |
| 2687 | >>> type(fl) |
| 2688 | <class 'numpy.ma.MaskedIterator'> |
| 2689 | >>> for item in fl: |
| 2690 | ... print(item) |
| 2691 | ... |
| 2692 | 0 |
| 2693 | 1 |
| 2694 | 2 |
| 2695 | 3 |
| 2696 | 4 |
| 2697 | 5 |
| 2698 | |
| 2699 | Extracting more than a single element b indexing the `MaskedIterator` |
| 2700 | returns a masked array: |
| 2701 | |
| 2702 | >>> fl[2:4] |
| 2703 | masked_array(data = [2 3], |
| 2704 | mask = False, |
| 2705 | fill_value = 999999) |
| 2706 | |
| 2707 | """ |
| 2708 | |
| 2709 | def __init__(self, ma): |
| 2710 | self.ma = ma |
| 2711 | self.dataiter = ma._data.flat |
| 2712 | |
| 2713 | if ma._mask is nomask: |
| 2714 | self.maskiter = None |
| 2715 | else: |
| 2716 | self.maskiter = ma._mask.flat |
| 2717 |
no outgoing calls
no test coverage detected
searching dependent graphs…