Mask an array inside a given interval. Shortcut to ``masked_where``, where `condition` is True for `x` inside the interval [v1,v2] (v1 <= x <= v2). The boundaries `v1` and `v2` can be given in either order. See Also -------- masked_where : Mask where a condition is me
(x, v1, v2, copy=True)
| 2174 | |
| 2175 | |
| 2176 | def masked_inside(x, v1, v2, copy=True): |
| 2177 | """ |
| 2178 | Mask an array inside a given interval. |
| 2179 | |
| 2180 | Shortcut to ``masked_where``, where `condition` is True for `x` inside |
| 2181 | the interval [v1,v2] (v1 <= x <= v2). The boundaries `v1` and `v2` |
| 2182 | can be given in either order. |
| 2183 | |
| 2184 | See Also |
| 2185 | -------- |
| 2186 | masked_where : Mask where a condition is met. |
| 2187 | |
| 2188 | Notes |
| 2189 | ----- |
| 2190 | The array `x` is prefilled with its filling value. |
| 2191 | |
| 2192 | Examples |
| 2193 | -------- |
| 2194 | >>> import numpy as np |
| 2195 | >>> import numpy.ma as ma |
| 2196 | >>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1] |
| 2197 | >>> ma.masked_inside(x, -0.3, 0.3) |
| 2198 | masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1], |
| 2199 | mask=[False, False, True, True, False, False], |
| 2200 | fill_value=1e+20) |
| 2201 | |
| 2202 | The order of `v1` and `v2` doesn't matter. |
| 2203 | |
| 2204 | >>> ma.masked_inside(x, 0.3, -0.3) |
| 2205 | masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1], |
| 2206 | mask=[False, False, True, True, False, False], |
| 2207 | fill_value=1e+20) |
| 2208 | |
| 2209 | """ |
| 2210 | if v2 < v1: |
| 2211 | (v1, v2) = (v2, v1) |
| 2212 | xf = filled(x) |
| 2213 | condition = (xf >= v1) & (xf <= v2) |
| 2214 | return masked_where(condition, x, copy=copy) |
| 2215 | |
| 2216 | |
| 2217 | def masked_outside(x, v1, v2, copy=True): |
searching dependent graphs…