def transform(self, X): _check_X(X) assert self._rows_mean is not None assert self._rows_std is not None out = X.copy().astype('float32') zmuv_rows_apply_inplace(out.T, self._rows_mean, self._rows_std) out[~np.isfinite(out)] = 0 return out
def test_zmuv_rows(): arr = np.random.randn(10000, 100).astype(np.float32) # -- numpy reference gt = (arr - arr.mean(0)) / arr.std(0) # -- cython rows_mean, rows_std = zmuv_rows(arr.T) gv = (arr - rows_mean) / rows_std assert_allclose(gt, gv, rtol=RTOL, atol=ATOL) # inplace zmuv_rows_apply_inplace(arr.T, rows_mean, rows_std) assert_allclose(gt, arr, rtol=RTOL, atol=ATOL)