Return `a` where condition is ``True``. If condition is a `~ma.MaskedArray`, missing values are considered as ``False``. Parameters ---------- condition : var Boolean 1-d array selecting which entries to return. If len(condition)
(self, condition, axis=None, out=None)
| 3972 | return data |
| 3973 | |
| 3974 | def compress(self, condition, axis=None, out=None): |
| 3975 | """ |
| 3976 | Return `a` where condition is ``True``. |
| 3977 | |
| 3978 | If condition is a `~ma.MaskedArray`, missing values are considered |
| 3979 | as ``False``. |
| 3980 | |
| 3981 | Parameters |
| 3982 | ---------- |
| 3983 | condition : var |
| 3984 | Boolean 1-d array selecting which entries to return. If len(condition) |
| 3985 | is less than the size of a along the axis, then output is truncated |
| 3986 | to length of condition array. |
| 3987 | axis : {None, int}, optional |
| 3988 | Axis along which the operation must be performed. |
| 3989 | out : {None, ndarray}, optional |
| 3990 | Alternative output array in which to place the result. It must have |
| 3991 | the same shape as the expected output but the type will be cast if |
| 3992 | necessary. |
| 3993 | |
| 3994 | Returns |
| 3995 | ------- |
| 3996 | result : MaskedArray |
| 3997 | A :class:`~ma.MaskedArray` object. |
| 3998 | |
| 3999 | Notes |
| 4000 | ----- |
| 4001 | Please note the difference with :meth:`compressed` ! |
| 4002 | The output of :meth:`compress` has a mask, the output of |
| 4003 | :meth:`compressed` does not. |
| 4004 | |
| 4005 | Examples |
| 4006 | -------- |
| 4007 | >>> import numpy as np |
| 4008 | >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4) |
| 4009 | >>> x |
| 4010 | masked_array( |
| 4011 | data=[[1, --, 3], |
| 4012 | [--, 5, --], |
| 4013 | [7, --, 9]], |
| 4014 | mask=[[False, True, False], |
| 4015 | [ True, False, True], |
| 4016 | [False, True, False]], |
| 4017 | fill_value=999999) |
| 4018 | >>> x.compress([1, 0, 1]) |
| 4019 | masked_array(data=[1, 3], |
| 4020 | mask=[False, False], |
| 4021 | fill_value=999999) |
| 4022 | |
| 4023 | >>> x.compress([1, 0, 1], axis=1) |
| 4024 | masked_array( |
| 4025 | data=[[1, 3], |
| 4026 | [--, --], |
| 4027 | [7, 9]], |
| 4028 | mask=[[False, False], |
| 4029 | [ True, True], |
| 4030 | [False, False]], |
| 4031 | fill_value=999999) |