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


Python ma.masked_values方法代码示例

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


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

示例1: generate_stimulus_xor

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def generate_stimulus_xor(stim_times, gen_burst, n_inputs=2):
    inp_states = np.random.randint(2, size=(n_inputs, np.size(stim_times)))
    inp_spikes = []

    for times in ma.masked_values(inp_states, 0) * stim_times:
        # for each input (neuron): generate spikes according to state (=1) and stimulus time-grid
        spikes = np.concatenate([t + gen_burst() for t in times.compressed()])

        # round to simulation precision
        spikes *= 10
        spikes = spikes.round() + 1.0
        spikes = spikes / 10.0

        inp_spikes.append(spikes)

    # astype(int) could be omitted, because False/True has the same semantics
    targets = np.logical_xor(*inp_states).astype(int)

    return inp_spikes, targets 
开发者ID:IGITUGraz,项目名称:LSM,代码行数:21,代码来源:example.py

示例2: test_missing_data_model

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def test_missing_data_model(self):
        # source pymc3/pymc3/tests/test_missing.py
        data = ma.masked_values([1, 2, -1, 4, -1], value=-1)
        model = pm.Model()
        with model:
            x = pm.Normal("x", 1, 1)
            pm.Normal("y", x, 1, observed=data)
            trace = pm.sample(100, chains=2)

        # make sure that data is really missing
        (y_missing,) = model.missing_values
        assert y_missing.tag.test_value.shape == (2,)
        inference_data = from_pymc3(trace=trace, model=model)
        test_dict = {"posterior": ["x"], "observed_data": ["y"], "log_likelihood": ["y"]}
        fails = check_multiple_attrs(test_dict, inference_data)
        assert not fails 
开发者ID:arviz-devs,项目名称:arviz,代码行数:18,代码来源:test_data_pymc.py

示例3: read

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def read(self, output_tile, **kwargs):
        """
        Read existing process output.

        Parameters
        ----------
        output_tile : ``BufferedTile``
            must be member of output ``TilePyramid``

        Returns
        -------
        process output : ``BufferedTile`` with appended data
        """
        try:
            return ma.masked_values(
                read_raster_no_crs(
                    self.get_path(output_tile), indexes=(4 if self.old_band_num else 2)
                ),
                0
            )
        except FileNotFoundError:
            return self.empty(output_tile) 
开发者ID:ungarj,项目名称:mapchete,代码行数:24,代码来源:png_hillshade.py

示例4: empty

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def empty(self, process_tile):
        """
        Return empty data.

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``

        Returns
        -------
        empty data : array or list
            empty array with correct data type for raster data or empty list
            for vector data
        """
        return ma.masked_values(np.zeros(process_tile.shape), 0) 
开发者ID:ungarj,项目名称:mapchete,代码行数:18,代码来源:png_hillshade.py

示例5: geoMean

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def geoMean(array):
    '''
    Generate the geometric mean of a list or array,
    removing all zero-values but retaining total length
    '''
    if isinstance(array, pandas.core.frame.DataFrame):
        array = array.as_matrix()
    else:
        pass
    non_zero = ma.masked_values(array,
                                0)

    log_a = ma.log(non_zero)
    geom_mean = ma.exp(log_a.mean())

    return geom_mean 
开发者ID:CGATOxford,项目名称:CGATPipelines,代码行数:18,代码来源:PipelineWindows.py

示例6: friedmanchisquare

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def friedmanchisquare(*args):
    """Friedman Chi-Square is a non-parametric, one-way within-subjects ANOVA.
    This function calculates the Friedman Chi-square test for repeated measures
    and returns the result, along with the associated probability value.

    Each input is considered a given group. Ideally, the number of treatments
    among each group should be equal. If this is not the case, only the first
    n treatments are taken into account, where n is the number of treatments
    of the smallest group.
    If a group has some missing values, the corresponding treatments are masked
    in the other groups.
    The test statistic is corrected for ties.

    Masked values in one group are propagated to the other groups.

    Returns: chi-square statistic, associated p-value
    """
    data = argstoarray(*args).astype(float)
    k = len(data)
    if k < 3:
        raise ValueError("Less than 3 groups (%i): " % k +
                         "the Friedman test is NOT appropriate.")
    ranked = ma.masked_values(rankdata(data, axis=0), 0)
    if ranked._mask is not nomask:
        ranked = ma.mask_cols(ranked)
        ranked = ranked.compressed().reshape(k,-1).view(ndarray)
    else:
        ranked = ranked._data
    (k,n) = ranked.shape
    # Ties correction
    repeats = np.array([find_repeats(_) for _ in ranked.T], dtype=object)
    ties = repeats[repeats.nonzero()].reshape(-1,2)[:,-1].astype(int)
    tie_correction = 1 - (ties**3-ties).sum()/float(n*(k**3-k))
    #
    ssbg = np.sum((ranked.sum(-1) - n*(k+1)/2.)**2)
    chisq = ssbg * 12./(n*k*(k+1)) * 1./tie_correction
    return chisq, stats.chisqprob(chisq,k-1)

#-############################################################################-# 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:41,代码来源:mstats_basic.py

示例7: test_ma

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def test_ma():
    x = ma.array([1.0, 2, 3])
    assert K(x) == k('1.0 2 3')

    x = ma.masked_values([1.0, 0, 2], 0)
    assert K(x) == k('1 0n 2')

    s = ma.masked_values(0.0, 0)
    assert K(s) == k('0n') 
开发者ID:KxSystems,项目名称:pyq,代码行数:11,代码来源:test_numpy.py

示例8: _prepare_masked

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def _prepare_masked(data, masked, nodata, dtype):
    if data.shape == data.mask.shape:
        if masked:
            return ma.masked_values(data.astype(dtype, copy=False), nodata, copy=False)
        else:
            return ma.filled(data.astype(dtype, copy=False), nodata)
    else:
        if masked:
            return ma.masked_values(data.astype(dtype, copy=False), nodata, copy=False)
        else:
            return ma.filled(data.astype(dtype, copy=False), nodata) 
开发者ID:ungarj,项目名称:mapchete,代码行数:13,代码来源:raster.py

示例9: friedmanchisquare

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def friedmanchisquare(*args):
    """Friedman Chi-Square is a non-parametric, one-way within-subjects ANOVA.
    This function calculates the Friedman Chi-square test for repeated measures
    and returns the result, along with the associated probability value.

    Each input is considered a given group. Ideally, the number of treatments
    among each group should be equal. If this is not the case, only the first
    n treatments are taken into account, where n is the number of treatments
    of the smallest group.
    If a group has some missing values, the corresponding treatments are masked
    in the other groups.
    The test statistic is corrected for ties.

    Masked values in one group are propagated to the other groups.

    Returns
    -------
    statistic : float
        the test statistic.
    pvalue : float
        the associated p-value.

    """
    data = argstoarray(*args).astype(float)
    k = len(data)
    if k < 3:
        raise ValueError("Less than 3 groups (%i): " % k +
                         "the Friedman test is NOT appropriate.")

    ranked = ma.masked_values(rankdata(data, axis=0), 0)
    if ranked._mask is not nomask:
        ranked = ma.mask_cols(ranked)
        ranked = ranked.compressed().reshape(k,-1).view(ndarray)
    else:
        ranked = ranked._data
    (k,n) = ranked.shape
    # Ties correction
    repeats = [find_repeats(row) for row in ranked.T]
    ties = np.array([y for x, y in repeats if x.size > 0])
    tie_correction = 1 - (ties**3-ties).sum()/float(n*(k**3-k))

    ssbg = np.sum((ranked.sum(-1) - n*(k+1)/2.)**2)
    chisq = ssbg * 12./(n*k*(k+1)) * 1./tie_correction

    return FriedmanchisquareResult(chisq,
                                   distributions.chi2.sf(chisq, k-1)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:48,代码来源:mstats_basic.py

示例10: friedmanchisquare

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def friedmanchisquare(*args):
    """Friedman Chi-Square is a non-parametric, one-way within-subjects ANOVA.
    This function calculates the Friedman Chi-square test for repeated measures
    and returns the result, along with the associated probability value.

    Each input is considered a given group. Ideally, the number of treatments
    among each group should be equal. If this is not the case, only the first
    n treatments are taken into account, where n is the number of treatments
    of the smallest group.
    If a group has some missing values, the corresponding treatments are masked
    in the other groups.
    The test statistic is corrected for ties.

    Masked values in one group are propagated to the other groups.

    Returns
    -------
    statistic : float
        the test statistic.
    pvalue : float
        the associated p-value.

    """
    data = argstoarray(*args).astype(float)
    k = len(data)
    if k < 3:
        raise ValueError("Less than 3 groups (%i): " % k +
                         "the Friedman test is NOT appropriate.")

    ranked = ma.masked_values(rankdata(data, axis=0), 0)
    if ranked._mask is not nomask:
        ranked = ma.mask_cols(ranked)
        ranked = ranked.compressed().reshape(k,-1).view(ndarray)
    else:
        ranked = ranked._data
    (k,n) = ranked.shape
    # Ties correction
    repeats = np.array([find_repeats(_) for _ in ranked.T], dtype=object)
    ties = repeats[repeats.nonzero()].reshape(-1,2)[:,-1].astype(int)
    tie_correction = 1 - (ties**3-ties).sum()/float(n*(k**3-k))

    ssbg = np.sum((ranked.sum(-1) - n*(k+1)/2.)**2)
    chisq = ssbg * 12./(n*k*(k+1)) * 1./tie_correction

    return FriedmanchisquareResult(chisq,
                                   distributions.chi2.sf(chisq, k-1)) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:48,代码来源:mstats_basic.py

示例11: prepare_array

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_values [as 别名]
def prepare_array(data, masked=True, nodata=0, dtype="int16"):
    """
    Turn input data into a proper array for further usage.

    Output array is always 3-dimensional with the given data type. If the output
    is masked, the fill_value corresponds to the given nodata value and the
    nodata value will be burned into the data array.

    Parameters
    ----------
    data : array or iterable
        array (masked or normal) or iterable containing arrays
    nodata : integer or float
        nodata value (default: 0) used if input is not a masked array and
        for output array
    masked : bool
        return a NumPy Array or a NumPy MaskedArray (default: True)
    dtype : string
        data type of output array (default: "int16")

    Returns
    -------
    array : array
    """
    # input is iterable
    if isinstance(data, (list, tuple)):
        return _prepare_iterable(data, masked, nodata, dtype)

    # special case if a 2D single band is provided
    elif isinstance(data, np.ndarray) and data.ndim == 2:
        data = ma.expand_dims(data, axis=0)

    # input is a masked array
    if isinstance(data, ma.MaskedArray):
        return _prepare_masked(data, masked, nodata, dtype)

    # input is a NumPy array
    elif isinstance(data, np.ndarray):
        if masked:
            return ma.masked_values(data.astype(dtype, copy=False), nodata, copy=False)
        else:
            return data.astype(dtype, copy=False)
    else:
        raise ValueError(
            "Data must be array, masked array or iterable containing arrays. "
            "Current data: %s (%s)" % (data, type(data))
        ) 
开发者ID:ungarj,项目名称:mapchete,代码行数:49,代码来源:raster.py


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