MCPcopy Index your code
hub / github.com/numpy/numpy / test_compress

Method test_compress

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

Source from the content-addressed store, hash-verified

3466 assert_equal(m.mask, [0, 1] * 5)
3467
3468 def test_compress(self):
3469 # test compress
3470 a = masked_array([1., 2., 3., 4., 5.], fill_value=9999)
3471 condition = (a > 1.5) & (a < 3.5)
3472 assert_equal(a.compress(condition), [2., 3.])
3473
3474 a[[2, 3]] = masked
3475 b = a.compress(condition)
3476 assert_equal(b._data, [2., 3.])
3477 assert_equal(b._mask, [0, 1])
3478 assert_equal(b.fill_value, 9999)
3479 assert_equal(b, a[condition])
3480
3481 condition = (a < 4.)
3482 b = a.compress(condition)
3483 assert_equal(b._data, [1., 2., 3.])
3484 assert_equal(b._mask, [0, 0, 1])
3485 assert_equal(b.fill_value, 9999)
3486 assert_equal(b, a[condition])
3487
3488 a = masked_array([[10, 20, 30], [40, 50, 60]],
3489 mask=[[0, 0, 1], [1, 0, 0]])
3490 b = a.compress(a.ravel() >= 22)
3491 assert_equal(b._data, [30, 40, 50, 60])
3492 assert_equal(b._mask, [1, 1, 0, 0])
3493
3494 x = np.array([3, 1, 2])
3495 b = a.compress(x >= 2, axis=1)
3496 assert_equal(b._data, [[10, 30], [40, 60]])
3497 assert_equal(b._mask, [[0, 1], [1, 0]])
3498
3499 def test_compressed(self):
3500 # 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