MCPcopy
hub / github.com/numpy/numpy / test_2d_with_missing

Method test_2d_with_missing

numpy/ma/tests/test_extras.py:1380–1399  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1378 cov(x, x[::-1], rowvar=False, bias=True))
1379
1380 def test_2d_with_missing(self):
1381 # Test cov on 2D variable w/ missing value
1382 x = self._create_data()
1383 x[-1] = masked
1384 x = x.reshape(3, 4)
1385 valid = np.logical_not(getmaskarray(x)).astype(int)
1386 frac = np.dot(valid, valid.T)
1387 xf = (x - x.mean(1)[:, None]).filled(0)
1388 assert_almost_equal(cov(x),
1389 np.cov(xf) * (x.shape[1] - 1) / (frac - 1.))
1390 assert_almost_equal(cov(x, bias=True),
1391 np.cov(xf, bias=True) * x.shape[1] / frac)
1392 frac = np.dot(valid.T, valid)
1393 xf = (x - x.mean(0)).filled(0)
1394 assert_almost_equal(cov(x, rowvar=False),
1395 (np.cov(xf, rowvar=False) *
1396 (x.shape[0] - 1) / (frac - 1.)))
1397 assert_almost_equal(cov(x, rowvar=False, bias=True),
1398 (np.cov(xf, rowvar=False, bias=True) *
1399 x.shape[0] / frac))
1400
1401
1402class TestCorrcoef:

Callers

nothing calls this directly

Calls 9

_create_dataMethod · 0.95
getmaskarrayFunction · 0.90
assert_almost_equalFunction · 0.90
covFunction · 0.90
reshapeMethod · 0.80
astypeMethod · 0.80
dotMethod · 0.80
filledMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected