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

Method test_compress

numpy/ma/tests/test_core.py:3254–3283  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3252 assert_equal(m.mask, [0, 1] * 5)
3253
3254 def test_compress(self):
3255 # test compress
3256 a = masked_array([1., 2., 3., 4., 5.], fill_value=9999)
3257 condition = (a > 1.5) & (a < 3.5)
3258 assert_equal(a.compress(condition), [2., 3.])
3259
3260 a[[2, 3]] = masked
3261 b = a.compress(condition)
3262 assert_equal(b._data, [2., 3.])
3263 assert_equal(b._mask, [0, 1])
3264 assert_equal(b.fill_value, 9999)
3265 assert_equal(b, a[condition])
3266
3267 condition = (a < 4.)
3268 b = a.compress(condition)
3269 assert_equal(b._data, [1., 2., 3.])
3270 assert_equal(b._mask, [0, 0, 1])
3271 assert_equal(b.fill_value, 9999)
3272 assert_equal(b, a[condition])
3273
3274 a = masked_array([[10, 20, 30], [40, 50, 60]],
3275 mask=[[0, 0, 1], [1, 0, 0]])
3276 b = a.compress(a.ravel() >= 22)
3277 assert_equal(b._data, [30, 40, 50, 60])
3278 assert_equal(b._mask, [1, 1, 0, 0])
3279
3280 x = np.array([3, 1, 2])
3281 b = a.compress(x >= 2, axis=1)
3282 assert_equal(b._data, [[10, 30], [40, 60]])
3283 assert_equal(b._mask, [[0, 1], [1, 0]])
3284
3285 def test_compressed(self):
3286 # Tests compressed

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
compressMethod · 0.80
ravelMethod · 0.45

Tested by

no test coverage detected