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

Method test_2d_with_missing

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

Source from the content-addressed store, hash-verified

1277 cov(x, x[::-1], rowvar=False, bias=True))
1278
1279 def test_2d_with_missing(self):
1280 # Test cov on 2D variable w/ missing value
1281 x = self.data
1282 x[-1] = masked
1283 x = x.reshape(3, 4)
1284 valid = np.logical_not(getmaskarray(x)).astype(int)
1285 frac = np.dot(valid, valid.T)
1286 xf = (x - x.mean(1)[:, None]).filled(0)
1287 assert_almost_equal(cov(x),
1288 np.cov(xf) * (x.shape[1] - 1) / (frac - 1.))
1289 assert_almost_equal(cov(x, bias=True),
1290 np.cov(xf, bias=True) * x.shape[1] / frac)
1291 frac = np.dot(valid.T, valid)
1292 xf = (x - x.mean(0)).filled(0)
1293 assert_almost_equal(cov(x, rowvar=False),
1294 (np.cov(xf, rowvar=False) *
1295 (x.shape[0] - 1) / (frac - 1.)))
1296 assert_almost_equal(cov(x, rowvar=False, bias=True),
1297 (np.cov(xf, rowvar=False, bias=True) *
1298 x.shape[0] / frac))
1299
1300
1301class TestCorrcoef:

Callers

nothing calls this directly

Calls 8

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