MCPcopy Create free account
hub / github.com/numpy/numpy / masked_inside

Function masked_inside

numpy/ma/core.py:2112–2149  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2110
2111
2112def masked_inside(x, v1, v2, copy=True):
2113 """
2114 Mask an array inside a given interval.
2115
2116 Shortcut to ``masked_where``, where `condition` is True for `x` inside
2117 the interval [v1,v2] (v1 <= x <= v2). The boundaries `v1` and `v2`
2118 can be given in either order.
2119
2120 See Also
2121 --------
2122 masked_where : Mask where a condition is met.
2123
2124 Notes
2125 -----
2126 The array `x` is prefilled with its filling value.
2127
2128 Examples
2129 --------
2130 >>> import numpy.ma as ma
2131 >>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1]
2132 >>> ma.masked_inside(x, -0.3, 0.3)
2133 masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1],
2134 mask=[False, False, True, True, False, False],
2135 fill_value=1e+20)
2136
2137 The order of `v1` and `v2` doesn&#x27;t matter.
2138
2139 >>> ma.masked_inside(x, 0.3, -0.3)
2140 masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1],
2141 mask=[False, False, True, True, False, False],
2142 fill_value=1e+20)
2143
2144 """
2145 if v2 < v1:
2146 (v1, v2) = (v2, v1)
2147 xf = filled(x)
2148 condition = (xf >= v1) & (xf <= v2)
2149 return masked_where(condition, x, copy=copy)
2150
2151
2152def masked_outside(x, v1, v2, copy=True):

Callers 2

test_testOddFeaturesMethod · 0.90

Calls 2

filledFunction · 0.85
masked_whereFunction · 0.85

Tested by 2

test_testOddFeaturesMethod · 0.72