(self)
| 6369 | assert_almost_equal(res, tgt) |
| 6370 | |
| 6371 | def test_std_where(self): |
| 6372 | a = np.arange(25).reshape((5,5))[::-1] |
| 6373 | whf = np.array([[False, True, False, True, True], |
| 6374 | [True, False, True, False, True], |
| 6375 | [True, True, False, True, False], |
| 6376 | [True, False, True, True, False], |
| 6377 | [False, True, False, True, True]]) |
| 6378 | whp = np.array([[False], |
| 6379 | [False], |
| 6380 | [True], |
| 6381 | [True], |
| 6382 | [False]]) |
| 6383 | _cases = [ |
| 6384 | (0, True, 7.07106781*np.ones((5))), |
| 6385 | (1, True, 1.41421356*np.ones((5))), |
| 6386 | (0, whf, |
| 6387 | np.array([4.0824829 , 8.16496581, 5., 7.39509973, 8.49836586])), |
| 6388 | (0, whp, 2.5*np.ones((5))) |
| 6389 | ] |
| 6390 | for _ax, _wh, _res in _cases: |
| 6391 | assert_allclose(a.std(axis=_ax, where=_wh), _res) |
| 6392 | assert_allclose(np.std(a, axis=_ax, where=_wh), _res) |
| 6393 | |
| 6394 | a3d = np.arange(16).reshape((2, 2, 4)) |
| 6395 | _wh_partial = np.array([False, True, True, False]) |
| 6396 | _res = [[0.5, 0.5], [0.5, 0.5]] |
| 6397 | assert_allclose(a3d.std(axis=2, where=_wh_partial), |
| 6398 | np.array(_res)) |
| 6399 | assert_allclose(np.std(a3d, axis=2, where=_wh_partial), |
| 6400 | np.array(_res)) |
| 6401 | |
| 6402 | assert_allclose(a.std(axis=1, where=whf), |
| 6403 | np.std(a[whf].reshape((5,3)), axis=1)) |
| 6404 | assert_allclose(np.std(a, axis=1, where=whf), |
| 6405 | (a[whf].reshape((5,3))).std(axis=1)) |
| 6406 | assert_allclose(a.std(axis=0, where=whp), |
| 6407 | np.std(a[whp[:,0]], axis=0)) |
| 6408 | assert_allclose(np.std(a, axis=0, where=whp), |
| 6409 | (a[whp[:,0]]).std(axis=0)) |
| 6410 | with pytest.warns(RuntimeWarning) as w: |
| 6411 | assert_equal(a.std(where=False), np.nan) |
| 6412 | with pytest.warns(RuntimeWarning) as w: |
| 6413 | assert_equal(np.std(a, where=False), np.nan) |
| 6414 | |
| 6415 | def test_subclass(self): |
| 6416 | class TestArray(np.ndarray): |
nothing calls this directly
no test coverage detected