Return the data of a masked array as an ndarray. Return the data of `a` (if any) as an ndarray if `a` is a ``MaskedArray``, else return `a` as an ndarray or subclass (depending on `subok`) if not. Parameters ---------- a : array_like Input ``MaskedArray``, alternat
(a, subok=True)
| 718 | |
| 719 | |
| 720 | def getdata(a, subok=True): |
| 721 | """ |
| 722 | Return the data of a masked array as an ndarray. |
| 723 | |
| 724 | Return the data of `a` (if any) as an ndarray if `a` is a ``MaskedArray``, |
| 725 | else return `a` as an ndarray or subclass (depending on `subok`) if not. |
| 726 | |
| 727 | Parameters |
| 728 | ---------- |
| 729 | a : array_like |
| 730 | Input ``MaskedArray``, alternatively an ndarray or a subclass thereof. |
| 731 | subok : bool |
| 732 | Whether to force the output to be a `pure` ndarray (False) or to |
| 733 | return a subclass of ndarray if appropriate (True, default). |
| 734 | |
| 735 | See Also |
| 736 | -------- |
| 737 | getmask : Return the mask of a masked array, or nomask. |
| 738 | getmaskarray : Return the mask of a masked array, or full array of False. |
| 739 | |
| 740 | Examples |
| 741 | -------- |
| 742 | >>> import numpy as np |
| 743 | >>> import numpy.ma as ma |
| 744 | >>> a = ma.masked_equal([[1,2],[3,4]], 2) |
| 745 | >>> a |
| 746 | masked_array( |
| 747 | data=[[1, --], |
| 748 | [3, 4]], |
| 749 | mask=[[False, True], |
| 750 | [False, False]], |
| 751 | fill_value=2) |
| 752 | >>> ma.getdata(a) |
| 753 | array([[1, 2], |
| 754 | [3, 4]]) |
| 755 | |
| 756 | Equivalently use the ``MaskedArray`` `data` attribute. |
| 757 | |
| 758 | >>> a.data |
| 759 | array([[1, 2], |
| 760 | [3, 4]]) |
| 761 | |
| 762 | """ |
| 763 | try: |
| 764 | data = a._data |
| 765 | except AttributeError: |
| 766 | data = np.array(a, copy=None, subok=subok) |
| 767 | if not subok: |
| 768 | return data.view(ndarray) |
| 769 | return data |
| 770 | |
| 771 | |
| 772 | get_data = getdata |
no test coverage detected
searching dependent graphs…