Python numpy.nanvar() Examples
The following are 30
code examples of numpy.nanvar().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_nanfunctions.py From recruit with Apache License 2.0 | 7 votes |
def test_dtype_from_dtype(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type assert_(res is tgt)
Example #2
Source File: test_nanfunctions.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_dtype_from_dtype(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type assert_(res is tgt)
Example #3
Source File: test_nanfunctions.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_ddof_too_big(self): nanfuncs = [np.nanvar, np.nanstd] stdfuncs = [np.var, np.std] dsize = [len(d) for d in _rdat] for nf, rf in zip(nanfuncs, stdfuncs): for ddof in range(5): with suppress_warnings() as sup: sup.record(RuntimeWarning) sup.filter(np.ComplexWarning) tgt = [ddof >= d for d in dsize] res = nf(_ndat, axis=1, ddof=ddof) assert_equal(np.isnan(res), tgt) if any(tgt): assert_(len(sup.log) == 1) else: assert_(len(sup.log) == 0)
Example #4
Source File: test_nanfunctions.py From lambda-packs with MIT License | 6 votes |
def test_ddof_too_big(self): nanfuncs = [np.nanvar, np.nanstd] stdfuncs = [np.var, np.std] dsize = [len(d) for d in _rdat] for nf, rf in zip(nanfuncs, stdfuncs): for ddof in range(5): with suppress_warnings() as sup: sup.record(RuntimeWarning) sup.filter(np.ComplexWarning) tgt = [ddof >= d for d in dsize] res = nf(_ndat, axis=1, ddof=ddof) assert_equal(np.isnan(res), tgt) if any(tgt): assert_(len(sup.log) == 1) else: assert_(len(sup.log) == 0)
Example #5
Source File: subjective_model_test.py From sureal with Apache License 2.0 | 6 votes |
def test_observer_content_aware_subjective_model(self): subjective_model = MaximumLikelihoodEstimationModel.from_dataset_file( self.dataset_filepath) result = subjective_model.run_modeling(force_subjbias_zeromean=False) self.assertAlmostEqual(float(np.nansum(result['content_ambiguity'])), 2.653508643860357, places=4) self.assertAlmostEqual(float(np.nanvar(result['content_ambiguity'])), 0.0092892978862108271, places=4) self.assertAlmostEqual(float(np.sum(result['observer_bias'])), -0.020313188445860726, places=4) self.assertAlmostEqual(float(np.var(result['observer_bias'])), 0.091830942654165318, places=4) self.assertAlmostEqual(float(np.sum(result['observer_inconsistency'])), 11.232923468639161, places=4) self.assertAlmostEqual(float(np.var(result['observer_inconsistency'])), 0.027721095664357907, places=4) self.assertAlmostEqual(float(np.sum(result['quality_scores'])), 177.88599894484821, places=4) self.assertAlmostEqual(float(np.var(result['quality_scores'])), 1.4896077857605587, places=4) # self.assertAlmostEqual(np.nansum(result['content_ambiguity_std']), 0.30465244947706538, places=4) self.assertAlmostEqual(float(np.sum(result['observer_bias_std'])), 2.165903882505483, places=4) self.assertAlmostEqual(float(np.sum(result['observer_inconsistency_std'])), 27.520643824238352, places=4) self.assertAlmostEqual(float(np.sum(result['quality_scores_std'])), 5.7355563435912256, places=4)
Example #6
Source File: test_nanfunctions.py From lambda-packs with MIT License | 6 votes |
def test_dtype_from_char(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=c, axis=1).dtype.type res = nf(mat, dtype=c, axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=c, axis=None).dtype.type res = nf(mat, dtype=c, axis=None).dtype.type assert_(res is tgt)
Example #7
Source File: test_nanfunctions.py From lambda-packs with MIT License | 6 votes |
def test_dtype_from_dtype(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type assert_(res is tgt)
Example #8
Source File: test_nanfunctions.py From ImageFusion with MIT License | 6 votes |
def test_ddof_too_big(self): nanfuncs = [np.nanvar, np.nanstd] stdfuncs = [np.var, np.std] dsize = [len(d) for d in _rdat] for nf, rf in zip(nanfuncs, stdfuncs): for ddof in range(5): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') tgt = [ddof >= d for d in dsize] res = nf(_ndat, axis=1, ddof=ddof) assert_equal(np.isnan(res), tgt) if any(tgt): assert_(len(w) == 1) assert_(issubclass(w[0].category, RuntimeWarning)) else: assert_(len(w) == 0)
Example #9
Source File: test_nanfunctions.py From recruit with Apache License 2.0 | 6 votes |
def test_dtype_from_char(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=c, axis=1).dtype.type res = nf(mat, dtype=c, axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=c, axis=None).dtype.type res = nf(mat, dtype=c, axis=None).dtype.type assert_(res is tgt)
Example #10
Source File: moments.py From dynamo-release with BSD 3-Clause "New" or "Revised" License | 6 votes |
def calc_12_mom_labeling(data, t, calculate_2_mom=True): t_uniq = np.unique(t) m = np.zeros((data.shape[0], len(t_uniq))) if calculate_2_mom: v =np.zeros((data.shape[0], len(t_uniq))) for i in range(data.shape[0]): data_ = ( np.array(data[i].A.flatten(), dtype=float) if issparse(data) else np.array(data[i], dtype=float) ) # consider using the `adata.obs_vector`, `adata.var_vector` methods or accessing the array directly. m[i] = strat_mom(data_, t, np.nanmean) if calculate_2_mom: v[i] = strat_mom(data_, t, np.nanvar) return (m, v, t_uniq) if calculate_2_mom else (m, t_uniq)
Example #11
Source File: moments.py From dynamo-release with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, adata, time_key="Time", has_nan=False): # self.data = adata self.__dict__ = adata.__dict__ # calculate first and second moments from data self.times = np.array(self.obs[time_key].values, dtype=float) self.uniq_times = np.unique(self.times) nT = self.get_n_times() ng = self.get_n_genes() self.M = np.zeros((ng, nT)) # first moments (data) self.V = np.zeros((ng, nT)) # second moments (data) for g in tqdm(range(ng), desc="calculating 1/2 moments"): tmp = self[:, g].layers["new"] L = ( np.array(tmp.A, dtype=float) if issparse(tmp) else np.array(tmp, dtype=float) ) # consider using the `adata.obs_vector`, `adata.var_vector` methods or accessing the array directly. if has_nan: self.M[g] = strat_mom(L, self.times, np.nanmean) self.V[g] = strat_mom(L, self.times, np.nanvar) else: self.M[g] = strat_mom(L, self.times, np.mean) self.V[g] = strat_mom(L, self.times, np.var)
Example #12
Source File: test_nanfunctions.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_ddof_too_big(self): nanfuncs = [np.nanvar, np.nanstd] stdfuncs = [np.var, np.std] dsize = [len(d) for d in _rdat] for nf, rf in zip(nanfuncs, stdfuncs): for ddof in range(5): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') tgt = [ddof >= d for d in dsize] res = nf(_ndat, axis=1, ddof=ddof) assert_equal(np.isnan(res), tgt) if any(tgt): assert_(len(w) == 1) assert_(issubclass(w[0].category, RuntimeWarning)) else: assert_(len(w) == 0)
Example #13
Source File: test_nanfunctions.py From vnpy_crypto with MIT License | 6 votes |
def test_dtype_from_dtype(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type assert_(res is tgt)
Example #14
Source File: test_nanfunctions.py From vnpy_crypto with MIT License | 6 votes |
def test_dtype_from_char(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=c, axis=1).dtype.type res = nf(mat, dtype=c, axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=c, axis=None).dtype.type res = nf(mat, dtype=c, axis=None).dtype.type assert_(res is tgt)
Example #15
Source File: test_nanfunctions.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_dtype_from_char(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=c, axis=1).dtype.type res = nf(mat, dtype=c, axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=c, axis=None).dtype.type res = nf(mat, dtype=c, axis=None).dtype.type assert_(res is tgt)
Example #16
Source File: test_nanfunctions.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_dtype_from_dtype(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type assert_(res is tgt)
Example #17
Source File: test_nanfunctions.py From Computable with MIT License | 6 votes |
def test_ddof_too_big(self): nanfuncs = [np.nanvar, np.nanstd] stdfuncs = [np.var, np.std] dsize = [len(d) for d in _rdat] for nf, rf in zip(nanfuncs, stdfuncs): for ddof in range(5): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') tgt = [ddof >= d for d in dsize] res = nf(_ndat, axis=1, ddof=ddof) assert_equal(np.isnan(res), tgt) if any(tgt): assert_(len(w) == 1) assert_(issubclass(w[0].category, RuntimeWarning)) else: assert_(len(w) == 0)
Example #18
Source File: scaler.py From fancyimpute with Apache License 2.0 | 6 votes |
def residual(self, X_normalized): total = 0 if self.center_rows: row_means = np.nanmean(X_normalized, axis=1) total += (row_means ** 2).sum() if self.center_columns: column_means = np.nanmean(X_normalized, axis=0) total += (column_means ** 2).sum() if self.scale_rows: row_variances = np.nanvar(X_normalized, axis=1) row_variances[row_variances == 0] = 1.0 total += (np.log(row_variances) ** 2).sum() if self.scale_columns: column_variances = np.nanvar(X_normalized, axis=0) column_variances[column_variances == 0] = 1.0 total += (np.log(column_variances) ** 2).sum() return total
Example #19
Source File: test_nanfunctions.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_dtype_from_dtype(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type assert_(res is tgt)
Example #20
Source File: test_nanfunctions.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_dtype_from_char(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=c, axis=1).dtype.type res = nf(mat, dtype=c, axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=c, axis=None).dtype.type res = nf(mat, dtype=c, axis=None).dtype.type assert_(res is tgt)
Example #21
Source File: expressions.py From ad_examples with MIT License | 6 votes |
def __init__(self, vals=None): """Initializes the mean and variance of the Gaussian variable.""" DType.__init__(self) if vals is None: vals = [0, 1] # some dummy. This is more for information. # Ignore NaNs n = np.count_nonzero(~np.isnan(vals)) if n > 0: self.mean = np.nanmean(vals) self.variance = np.nanvar(vals) else: self.mean = 0 self.variance = 0
Example #22
Source File: scaler.py From ME-Net with MIT License | 6 votes |
def residual(self, X_normalized): total = 0 if self.center_rows: row_means = np.nanmean(X_normalized, axis=1) total += (row_means ** 2).sum() if self.center_columns: column_means = np.nanmean(X_normalized, axis=0) total += (column_means ** 2).sum() if self.scale_rows: row_variances = np.nanvar(X_normalized, axis=1) row_variances[row_variances == 0] = 1.0 total += (np.log(row_variances) ** 2).sum() if self.scale_columns: column_variances = np.nanvar(X_normalized, axis=0) column_variances[column_variances == 0] = 1.0 total += (np.log(column_variances) ** 2).sum() return total
Example #23
Source File: test_nanfunctions.py From pySINDy with MIT License | 6 votes |
def test_dtype_from_char(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=c, axis=1).dtype.type res = nf(mat, dtype=c, axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=c, axis=None).dtype.type res = nf(mat, dtype=c, axis=None).dtype.type assert_(res is tgt)
Example #24
Source File: test_nanfunctions.py From pySINDy with MIT License | 6 votes |
def test_dtype_from_dtype(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type assert_(res is tgt)
Example #25
Source File: meanvar.py From cupy with MIT License | 6 votes |
def nanvar(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): """Returns the variance along an axis ignoring NaN values. Args: a (cupy.ndarray): Array to compute variance. axis (int): Along which axis to compute variance. The flattened array is used by default. dtype: Data type specifier. out (cupy.ndarray): Output array. keepdims (bool): If ``True``, the axis is remained as an axis of size one. Returns: cupy.ndarray: The variance of the input array along the axis. .. seealso:: :func:`numpy.nanvar` """ if a.dtype.kind in 'biu': return a.var(axis=axis, dtype=dtype, out=out, ddof=ddof, keepdims=keepdims) # TODO(okuta): check type return _statistics._nanvar( a, axis=axis, dtype=dtype, out=out, ddof=ddof, keepdims=keepdims)
Example #26
Source File: test_nanfunctions.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_dtype_from_dtype(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type assert_(res is tgt)
Example #27
Source File: test_nanfunctions.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_dtype_from_char(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=c, axis=1).dtype.type res = nf(mat, dtype=c, axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=c, axis=None).dtype.type res = nf(mat, dtype=c, axis=None).dtype.type assert_(res is tgt)
Example #28
Source File: test_nanfunctions.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_dtype_from_char(self): mat = np.eye(3) codes = 'efdgFDG' for nf, rf in zip(self.nanfuncs, self.stdfuncs): for c in codes: with suppress_warnings() as sup: if nf in {np.nanstd, np.nanvar} and c in 'FDG': # Giving the warning is a small bug, see gh-8000 sup.filter(np.ComplexWarning) tgt = rf(mat, dtype=c, axis=1).dtype.type res = nf(mat, dtype=c, axis=1).dtype.type assert_(res is tgt) # scalar case tgt = rf(mat, dtype=c, axis=None).dtype.type res = nf(mat, dtype=c, axis=None).dtype.type assert_(res is tgt)
Example #29
Source File: test_nanfunctions.py From vnpy_crypto with MIT License | 6 votes |
def test_ddof_too_big(self): nanfuncs = [np.nanvar, np.nanstd] stdfuncs = [np.var, np.std] dsize = [len(d) for d in _rdat] for nf, rf in zip(nanfuncs, stdfuncs): for ddof in range(5): with suppress_warnings() as sup: sup.record(RuntimeWarning) sup.filter(np.ComplexWarning) tgt = [ddof >= d for d in dsize] res = nf(_ndat, axis=1, ddof=ddof) assert_equal(np.isnan(res), tgt) if any(tgt): assert_(len(sup.log) == 1) else: assert_(len(sup.log) == 0)
Example #30
Source File: test_sdc_numpy.py From sdc with BSD 2-Clause "Simplified" License | 5 votes |
def test_nanvar(self): def ref_impl(a): return np.nanvar(a) def sdc_impl(a): return numpy_like.nanvar(a) self.check_reduction_basic(ref_impl, sdc_impl, comparator=np.testing.assert_array_almost_equal)