Mask rows and/or columns of a 2D array that contain masked values. Mask whole rows and/or columns of a 2D array that contain masked values. The masking behavior is selected using the `axis` parameter. - If `axis` is None, rows *and* columns are masked. - If `axis` is
(a, axis=None)
| 955 | |
| 956 | |
| 957 | def mask_rowcols(a, axis=None): |
| 958 | """ |
| 959 | Mask rows and/or columns of a 2D array that contain masked values. |
| 960 | |
| 961 | Mask whole rows and/or columns of a 2D array that contain |
| 962 | masked values. The masking behavior is selected using the |
| 963 | `axis` parameter. |
| 964 | |
| 965 | - If `axis` is None, rows *and* columns are masked. |
| 966 | - If `axis` is 0, only rows are masked. |
| 967 | - If `axis` is 1 or -1, only columns are masked. |
| 968 | |
| 969 | Parameters |
| 970 | ---------- |
| 971 | a : array_like, MaskedArray |
| 972 | The array to mask. If not a MaskedArray instance (or if no array |
| 973 | elements are masked), the result is a MaskedArray with `mask` set |
| 974 | to `nomask` (False). Must be a 2D array. |
| 975 | axis : int, optional |
| 976 | Axis along which to perform the operation. If None, applies to a |
| 977 | flattened version of the array. |
| 978 | |
| 979 | Returns |
| 980 | ------- |
| 981 | a : MaskedArray |
| 982 | A modified version of the input array, masked depending on the value |
| 983 | of the `axis` parameter. |
| 984 | |
| 985 | Raises |
| 986 | ------ |
| 987 | NotImplementedError |
| 988 | If input array `a` is not 2D. |
| 989 | |
| 990 | See Also |
| 991 | -------- |
| 992 | mask_rows : Mask rows of a 2D array that contain masked values. |
| 993 | mask_cols : Mask cols of a 2D array that contain masked values. |
| 994 | masked_where : Mask where a condition is met. |
| 995 | |
| 996 | Notes |
| 997 | ----- |
| 998 | The input array's mask is modified by this function. |
| 999 | |
| 1000 | Examples |
| 1001 | -------- |
| 1002 | >>> import numpy.ma as ma |
| 1003 | >>> a = np.zeros((3, 3), dtype=int) |
| 1004 | >>> a[1, 1] = 1 |
| 1005 | >>> a |
| 1006 | array([[0, 0, 0], |
| 1007 | [0, 1, 0], |
| 1008 | [0, 0, 0]]) |
| 1009 | >>> a = ma.masked_equal(a, 1) |
| 1010 | >>> a |
| 1011 | masked_array( |
| 1012 | data=[[0, 0, 0], |
| 1013 | [0, --, 0], |
| 1014 | [0, 0, 0]], |