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

Method test_std_where

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

Source from the content-addressed store, hash-verified

7339 assert_almost_equal(res, tgt)
7340
7341 def test_std_where(self):
7342 a = np.arange(25).reshape((5, 5))[::-1]
7343 whf = np.array([[False, True, False, True, True],
7344 [True, False, True, False, True],
7345 [True, True, False, True, False],
7346 [True, False, True, True, False],
7347 [False, True, False, True, True]])
7348 whp = np.array([[False],
7349 [False],
7350 [True],
7351 [True],
7352 [False]])
7353 _cases = [
7354 (0, True, 7.07106781 * np.ones(5)),
7355 (1, True, 1.41421356 * np.ones(5)),
7356 (0, whf,
7357 np.array([4.0824829, 8.16496581, 5., 7.39509973, 8.49836586])),
7358 (0, whp, 2.5 * np.ones(5))
7359 ]
7360 for _ax, _wh, _res in _cases:
7361 assert_allclose(a.std(axis=_ax, where=_wh), _res)
7362 assert_allclose(np.std(a, axis=_ax, where=_wh), _res)
7363
7364 a3d = np.arange(16).reshape((2, 2, 4))
7365 _wh_partial = np.array([False, True, True, False])
7366 _res = [[0.5, 0.5], [0.5, 0.5]]
7367 assert_allclose(a3d.std(axis=2, where=_wh_partial),
7368 np.array(_res))
7369 assert_allclose(np.std(a3d, axis=2, where=_wh_partial),
7370 np.array(_res))
7371
7372 assert_allclose(a.std(axis=1, where=whf),
7373 np.std(a[whf].reshape((5, 3)), axis=1))
7374 assert_allclose(np.std(a, axis=1, where=whf),
7375 (a[whf].reshape((5, 3))).std(axis=1))
7376 assert_allclose(a.std(axis=0, where=whp),
7377 np.std(a[whp[:, 0]], axis=0))
7378 assert_allclose(np.std(a, axis=0, where=whp),
7379 (a[whp[:, 0]]).std(axis=0))
7380 with pytest.warns(RuntimeWarning) as w:
7381 assert_equal(a.std(where=False), np.nan)
7382 with pytest.warns(RuntimeWarning) as w:
7383 assert_equal(np.std(a, where=False), np.nan)
7384
7385 def test_subclass(self):
7386 class TestArray(np.ndarray):

Callers

nothing calls this directly

Calls 4

assert_allcloseFunction · 0.90
assert_equalFunction · 0.90
reshapeMethod · 0.80
stdMethod · 0.45

Tested by

no test coverage detected