当前位置: 首页>>代码示例>>Python>>正文


Python numpy.nanvar方法代码示例

本文整理汇总了Python中numpy.nanvar方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.nanvar方法的具体用法?Python numpy.nanvar怎么用?Python numpy.nanvar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.nanvar方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dtype_from_dtype

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_nanfunctions.py

示例2: test_dtype_from_char

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_nanfunctions.py

示例3: test_ddof_too_big

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:test_nanfunctions.py

示例4: test_ddof_too_big

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:18,代码来源:test_nanfunctions.py

示例5: nanvar

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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) 
开发者ID:cupy,项目名称:cupy,代码行数:27,代码来源:meanvar.py

示例6: residual

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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 
开发者ID:YyzHarry,项目名称:ME-Net,代码行数:23,代码来源:scaler.py

示例7: __init__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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 
开发者ID:shubhomoydas,项目名称:ad_examples,代码行数:18,代码来源:expressions.py

示例8: test_observer_content_aware_subjective_model

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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) 
开发者ID:Netflix,项目名称:sureal,代码行数:23,代码来源:subjective_model_test.py

示例9: calc_12_mom_labeling

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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) 
开发者ID:aristoteleo,项目名称:dynamo-release,代码行数:18,代码来源:moments.py

示例10: __init__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
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) 
开发者ID:aristoteleo,项目名称:dynamo-release,代码行数:25,代码来源:moments.py

示例11: _calc_var

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanvar [as 别名]
def _calc_var(self):

        if self.data is None:
            raise RuntimeError('Fit the data model first.')

        data = self.data.T

        # variance calc
        var = np.nanvar(data, axis=1)
        total_var = var.sum()
        self.var_exp = self.eig_vals.cumsum() / total_var 
开发者ID:allentran,项目名称:pca-magic,代码行数:13,代码来源:_ppca.py


注:本文中的numpy.nanvar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。