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

Method test_put

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

Source from the content-addressed store, hash-verified

3359
3360 @suppress_copy_mask_on_assignment
3361 def test_put(self):
3362 # Tests put.
3363 d = arange(5)
3364 n = [0, 0, 0, 1, 1]
3365 m = make_mask(n)
3366 x = array(d, mask=m)
3367 assert_(x[3] is masked)
3368 assert_(x[4] is masked)
3369 x[[1, 4]] = [10, 40]
3370 assert_(x[3] is masked)
3371 assert_(x[4] is not masked)
3372 assert_equal(x, [0, 10, 2, -1, 40])
3373
3374 x = masked_array(arange(10), mask=[1, 0, 0, 0, 0] * 2)
3375 i = [0, 2, 4, 6]
3376 x.put(i, [6, 4, 2, 0])
3377 assert_equal(x, asarray([6, 1, 4, 3, 2, 5, 0, 7, 8, 9, ]))
3378 assert_equal(x.mask, [0, 0, 0, 0, 0, 1, 0, 0, 0, 0])
3379 x.put(i, masked_array([0, 2, 4, 6], [1, 0, 1, 0]))
3380 assert_array_equal(x, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ])
3381 assert_equal(x.mask, [1, 0, 0, 0, 1, 1, 0, 0, 0, 0])
3382
3383 x = masked_array(arange(10), mask=[1, 0, 0, 0, 0] * 2)
3384 put(x, i, [6, 4, 2, 0])
3385 assert_equal(x, asarray([6, 1, 4, 3, 2, 5, 0, 7, 8, 9, ]))
3386 assert_equal(x.mask, [0, 0, 0, 0, 0, 1, 0, 0, 0, 0])
3387 put(x, i, masked_array([0, 2, 4, 6], [1, 0, 1, 0]))
3388 assert_array_equal(x, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ])
3389 assert_equal(x.mask, [1, 0, 0, 0, 1, 1, 0, 0, 0, 0])
3390
3391 def test_put_nomask(self):
3392 # GitHub issue 6425

Callers

nothing calls this directly

Calls 9

make_maskFunction · 0.90
arrayFunction · 0.90
assert_equalFunction · 0.90
asarrayFunction · 0.90
assert_array_equalFunction · 0.90
putFunction · 0.90
arangeFunction · 0.85
putMethod · 0.80
assert_Function · 0.50

Tested by

no test coverage detected