MCPcopy
hub / github.com/numpy/numpy / test_var_where

Method test_var_where

numpy/_core/tests/test_multiarray.py:7296–7331  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

7294 np.arange(10).var(axis=2)
7295
7296 def test_var_where(self):
7297 a = np.arange(25).reshape((5, 5))
7298 wh_full = np.array([[False, True, False, True, True],
7299 [True, False, True, True, False],
7300 [True, True, False, False, True],
7301 [False, True, True, False, True],
7302 [True, False, True, True, False]])
7303 wh_partial = np.array([[False],
7304 [True],
7305 [True],
7306 [False],
7307 [True]])
7308 _cases = [(0, True, [50., 50., 50., 50., 50.]),
7309 (1, True, [2., 2., 2., 2., 2.])]
7310 for _ax, _wh, _res in _cases:
7311 assert_allclose(a.var(axis=_ax, where=_wh),
7312 np.array(_res))
7313 assert_allclose(np.var(a, axis=_ax, where=_wh),
7314 np.array(_res))
7315
7316 a3d = np.arange(16).reshape((2, 2, 4))
7317 _wh_partial = np.array([False, True, True, False])
7318 _res = [[0.25, 0.25], [0.25, 0.25]]
7319 assert_allclose(a3d.var(axis=2, where=_wh_partial),
7320 np.array(_res))
7321 assert_allclose(np.var(a3d, axis=2, where=_wh_partial),
7322 np.array(_res))
7323
7324 assert_allclose(np.var(a, axis=1, where=wh_full),
7325 np.var(a[wh_full].reshape((5, 3)), axis=1))
7326 assert_allclose(np.var(a, axis=0, where=wh_partial),
7327 np.var(a[wh_partial[:, 0]], axis=0))
7328 with pytest.warns(RuntimeWarning) as w:
7329 assert_equal(a.var(where=False), np.nan)
7330 with pytest.warns(RuntimeWarning) as w:
7331 assert_equal(np.var(a, where=False), np.nan)
7332
7333 def test_std_values(self):
7334 rmat, cmat, omat = self._create_data()

Callers

nothing calls this directly

Calls 4

assert_allcloseFunction · 0.90
assert_equalFunction · 0.90
reshapeMethod · 0.80
varMethod · 0.45

Tested by

no test coverage detected