Mask an array outside a given interval. Shortcut to ``masked_where``, where `condition` is True for `x` outside the interval [v1,v2] (x < v1)|(x > v2). The boundaries `v1` and `v2` can be given in either order. See Also -------- masked_where : Mask where a condition is
(x, v1, v2, copy=True)
| 2150 | |
| 2151 | |
| 2152 | def masked_outside(x, v1, v2, copy=True): |
| 2153 | """ |
| 2154 | Mask an array outside a given interval. |
| 2155 | |
| 2156 | Shortcut to ``masked_where``, where `condition` is True for `x` outside |
| 2157 | the interval [v1,v2] (x < v1)|(x > v2). |
| 2158 | The boundaries `v1` and `v2` can be given in either order. |
| 2159 | |
| 2160 | See Also |
| 2161 | -------- |
| 2162 | masked_where : Mask where a condition is met. |
| 2163 | |
| 2164 | Notes |
| 2165 | ----- |
| 2166 | The array `x` is prefilled with its filling value. |
| 2167 | |
| 2168 | Examples |
| 2169 | -------- |
| 2170 | >>> import numpy.ma as ma |
| 2171 | >>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1] |
| 2172 | >>> ma.masked_outside(x, -0.3, 0.3) |
| 2173 | masked_array(data=[--, --, 0.01, 0.2, --, --], |
| 2174 | mask=[ True, True, False, False, True, True], |
| 2175 | fill_value=1e+20) |
| 2176 | |
| 2177 | The order of `v1` and `v2` doesn't matter. |
| 2178 | |
| 2179 | >>> ma.masked_outside(x, 0.3, -0.3) |
| 2180 | masked_array(data=[--, --, 0.01, 0.2, --, --], |
| 2181 | mask=[ True, True, False, False, True, True], |
| 2182 | fill_value=1e+20) |
| 2183 | |
| 2184 | """ |
| 2185 | if v2 < v1: |
| 2186 | (v1, v2) = (v2, v1) |
| 2187 | xf = filled(x) |
| 2188 | condition = (xf < v1) | (xf > v2) |
| 2189 | return masked_where(condition, x, copy=copy) |
| 2190 | |
| 2191 | |
| 2192 | def masked_object(x, value, copy=True, shrink=True): |