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

Method test_count

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

Source from the content-addressed store, hash-verified

5536 testkeepdims(f, a, d)
5537
5538 def test_count(self):
5539 # test np.ma.count specially
5540
5541 d = np.arange(24.0).reshape((2, 3, 4))
5542 m = np.zeros(24, dtype=bool).reshape((2, 3, 4))
5543 m[:, 0, :] = True
5544 a = np.ma.array(d, mask=m)
5545
5546 assert_equal(count(a), 16)
5547 assert_equal(count(a, axis=1), 2 * ones((2, 4)))
5548 assert_equal(count(a, axis=(0, 1)), 4 * ones((4,)))
5549 assert_equal(count(a, keepdims=True), 16 * ones((1, 1, 1)))
5550 assert_equal(count(a, axis=1, keepdims=True), 2 * ones((2, 1, 4)))
5551 assert_equal(count(a, axis=(0, 1), keepdims=True), 4 * ones((1, 1, 4)))
5552 assert_equal(count(a, axis=-2), 2 * ones((2, 4)))
5553 assert_raises(ValueError, count, a, axis=(1, 1))
5554 assert_raises(AxisError, count, a, axis=3)
5555
5556 # check the 'nomask' path
5557 a = np.ma.array(d, mask=nomask)
5558
5559 assert_equal(count(a), 24)
5560 assert_equal(count(a, axis=1), 3 * ones((2, 4)))
5561 assert_equal(count(a, axis=(0, 1)), 6 * ones((4,)))
5562 assert_equal(count(a, keepdims=True), 24 * ones((1, 1, 1)))
5563 assert_equal(np.ndim(count(a, keepdims=True)), 3)
5564 assert_equal(count(a, axis=1, keepdims=True), 3 * ones((2, 1, 4)))
5565 assert_equal(count(a, axis=(0, 1), keepdims=True), 6 * ones((1, 1, 4)))
5566 assert_equal(count(a, axis=-2), 3 * ones((2, 4)))
5567 assert_raises(ValueError, count, a, axis=(1, 1))
5568 assert_raises(AxisError, count, a, axis=3)
5569
5570 # check the 'masked' singleton
5571 assert_equal(count(np.ma.masked), 0)
5572
5573 # check 0-d arrays do not allow axis > 0
5574 assert_raises(AxisError, count, np.ma.array(1), axis=1)
5575
5576
5577class TestMaskedConstant:

Callers

nothing calls this directly

Calls 5

assert_equalFunction · 0.90
countFunction · 0.90
onesFunction · 0.90
assert_raisesFunction · 0.90
reshapeMethod · 0.80

Tested by

no test coverage detected