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

Method test_count

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

Source from the content-addressed store, hash-verified

5275 testkeepdims(f, a, d)
5276
5277 def test_count(self):
5278 # test np.ma.count specially
5279
5280 d = np.arange(24.0).reshape((2,3,4))
5281 m = np.zeros(24, dtype=bool).reshape((2,3,4))
5282 m[:,0,:] = True
5283 a = np.ma.array(d, mask=m)
5284
5285 assert_equal(count(a), 16)
5286 assert_equal(count(a, axis=1), 2*ones((2,4)))
5287 assert_equal(count(a, axis=(0,1)), 4*ones((4,)))
5288 assert_equal(count(a, keepdims=True), 16*ones((1,1,1)))
5289 assert_equal(count(a, axis=1, keepdims=True), 2*ones((2,1,4)))
5290 assert_equal(count(a, axis=(0,1), keepdims=True), 4*ones((1,1,4)))
5291 assert_equal(count(a, axis=-2), 2*ones((2,4)))
5292 assert_raises(ValueError, count, a, axis=(1,1))
5293 assert_raises(np.AxisError, count, a, axis=3)
5294
5295 # check the 'nomask' path
5296 a = np.ma.array(d, mask=nomask)
5297
5298 assert_equal(count(a), 24)
5299 assert_equal(count(a, axis=1), 3*ones((2,4)))
5300 assert_equal(count(a, axis=(0,1)), 6*ones((4,)))
5301 assert_equal(count(a, keepdims=True), 24*ones((1,1,1)))
5302 assert_equal(np.ndim(count(a, keepdims=True)), 3)
5303 assert_equal(count(a, axis=1, keepdims=True), 3*ones((2,1,4)))
5304 assert_equal(count(a, axis=(0,1), keepdims=True), 6*ones((1,1,4)))
5305 assert_equal(count(a, axis=-2), 3*ones((2,4)))
5306 assert_raises(ValueError, count, a, axis=(1,1))
5307 assert_raises(np.AxisError, count, a, axis=3)
5308
5309 # check the 'masked' singleton
5310 assert_equal(count(np.ma.masked), 0)
5311
5312 # check 0-d arrays do not allow axis > 0
5313 assert_raises(np.AxisError, count, np.ma.array(1), axis=1)
5314
5315
5316class TestMaskedConstant:

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected