def test_std_with_ddof(self): x = np.random.uniform(0, 10, (20, 100)) for axis in [None, 0, 1]: np.testing.assert_almost_equal( np.std(x, axis=axis, ddof=10), std(csr_matrix(x), axis=axis, ddof=10), )
def test_std_with_ddof(self): x = np.random.uniform(0, 10, (20, 100)) for axis in [None, 0, 1]: np.testing.assert_almost_equal( np.std(x, axis=axis, ddof=10), std(csr_matrix(x), axis=axis, ddof=10), )
def _standardize(X, tol=1e-8): """ Standardize matrix X avoiding NaNs and small values. """ s = ut.std(X, axis=0) m = np.zeros(*s.shape) valid = s > tol m[np.logical_not(valid)] = 0 m[valid] = 1.0 / s[valid] return (X - X.mean(axis=0)) * m
def test_std(self): for data in self.data: for axis in chain((None,), range(len(data.shape))): # Can't use array_equal here due to differences on 1e-16 level np.testing.assert_array_almost_equal( std(csr_matrix(data), axis=axis), np.std(data, axis=axis) )
def test_std(self): for data in self.data: for axis in chain((None,), range(len(data.shape))): # Can't use array_equal here due to differences on 1e-16 level np.testing.assert_array_almost_equal( std(csr_matrix(data), axis=axis), np.std(data, axis=axis) )