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


Python ma.mask_or方法代码示例

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


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

示例1: set_UVC

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import mask_or [as 别名]
def set_UVC(self, U, V, C=None):
        U = ma.masked_invalid(U, copy=False).ravel()
        V = ma.masked_invalid(V, copy=False).ravel()
        mask = ma.mask_or(U.mask, V.mask, copy=False, shrink=True)
        if C is not None:
            C = ma.masked_invalid(C, copy=False).ravel()
            mask = ma.mask_or(mask, C.mask, copy=False, shrink=True)
            if mask is ma.nomask:
                C = C.filled()
            else:
                C = ma.array(C, mask=mask, copy=False)
        self.U = U.filled(1)
        self.V = V.filled(1)
        self.Umask = mask
        if C is not None:
            self.set_array(C)
        self._new_UV = True 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:quiver.py

示例2: pointbiserialr

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import mask_or [as 别名]
def pointbiserialr(x, y):
    x = ma.fix_invalid(x, copy=True).astype(bool)
    y = ma.fix_invalid(y, copy=True).astype(float)
    # Get rid of the missing data ..........
    m = ma.mask_or(ma.getmask(x), ma.getmask(y))
    if m is not nomask:
        unmask = np.logical_not(m)
        x = x[unmask]
        y = y[unmask]
    #
    n = len(x)
    # phat is the fraction of x values that are True
    phat = x.sum() / float(n)
    y0 = y[~x]  # y-values where x is False
    y1 = y[x]  # y-values where x is True
    y0m = y0.mean()
    y1m = y1.mean()
    #
    rpb = (y1m - y0m)*np.sqrt(phat * (1-phat)) / y.std()
    #
    df = n-2
    t = rpb*ma.sqrt(df/(1.0-rpb**2))
    prob = betai(0.5*df, 0.5, df/(df+t*t))
    return rpb, prob 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:mstats_basic.py

示例3: set_UVC

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import mask_or [as 别名]
def set_UVC(self, U, V, C=None):
        # We need to ensure we have a copy, not a reference
        # to an array that might change before draw().
        U = ma.masked_invalid(U, copy=True).ravel()
        V = ma.masked_invalid(V, copy=True).ravel()
        mask = ma.mask_or(U.mask, V.mask, copy=False, shrink=True)
        if C is not None:
            C = ma.masked_invalid(C, copy=True).ravel()
            mask = ma.mask_or(mask, C.mask, copy=False, shrink=True)
            if mask is ma.nomask:
                C = C.filled()
            else:
                C = ma.array(C, mask=mask, copy=False)
        self.U = U.filled(1)
        self.V = V.filled(1)
        self.Umask = mask
        if C is not None:
            self.set_array(C)
        self._new_UV = True
        self.stale = True 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:22,代码来源:quiver.py

示例4: __init__

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import mask_or [as 别名]
def __init__(self,vals,vals_dmin,vals_dmax,mask=ma.nomask):
        super(UncertContainer, self).__init__()
        
        # If input data already masked arrays extract unmasked data
        if ma.isMaskedArray(vals): 
            vals = vals.data
        if ma.isMaskedArray(vals_dmin):
            vals_dmin = vals_dmin.data
        if ma.isMaskedArray(vals_dmax):
            vals_dmax = vals_dmax.data
        
        # Adjust negative values
        ineg = np.where(vals_dmin <= 0.0)
        vals_dmin[ineg] = TOL*vals[ineg]

        # Calculate weight based on fractional uncertainty 
        diff = vals_dmax - vals_dmin
        diff_m = ma.masked_where(vals_dmax == vals_dmin,diff)        

        self.vals = ma.masked_where(vals == 0.0,vals)

        self.wt = (self.vals/diff_m)**2
        self.uncert = diff_m/self.vals

        self.wt.fill_value = np.inf
        self.uncert.fill_vaule = np.inf

        assert np.all(self.wt.mask == self.uncert.mask)
        
        # Mask data if uncertainty is not finite or if any of the inputs were
        # already masked

        mm = ma.mask_or(self.wt.mask,mask)
        
        self.vals.mask = mm
        self.wt.mask = mm
        self.uncert.mask = mm
        self.dmin = ma.array(vals_dmin,mask=mm,fill_value=np.inf)
        self.dmax = ma.array(vals_dmax,mask=mm,fill_value=np.inf)

        self.mask = ma.getmaskarray(self.vals) 
开发者ID:westpa,项目名称:westpa,代码行数:43,代码来源:UncertMath.py

示例5: linregress

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import mask_or [as 别名]
def linregress(x, y=None):
    """
    Linear regression calculation

    Note that the non-masked version is used, and that this docstring is
    replaced by the non-masked docstring + some info on missing data.

    """
    if y is None:
        x = ma.array(x)
        if x.shape[0] == 2:
            x, y = x
        elif x.shape[1] == 2:
            x, y = x.T
        else:
            msg = ("If only `x` is given as input, it has to be of shape "
                   "(2, N) or (N, 2), provided shape was %s" % str(x.shape))
            raise ValueError(msg)
    else:
        x = ma.array(x)
        y = ma.array(y)

    x = x.flatten()
    y = y.flatten()

    m = ma.mask_or(ma.getmask(x), ma.getmask(y), shrink=False)
    if m is not nomask:
        x = ma.array(x, mask=m)
        y = ma.array(y, mask=m)
        if np.any(~m):
            slope, intercept, r, prob, sterrest = stats_linregress(x.data[~m],
                                                                   y.data[~m])
        else:
            # All data is masked
            return None, None, None, None, None
    else:
        slope, intercept, r, prob, sterrest = stats_linregress(x.data, y.data)

    return LinregressResult(slope, intercept, r, prob, sterrest) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:41,代码来源:mstats_basic.py

示例6: linregress

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import mask_or [as 别名]
def linregress(*args):
    if len(args) == 1:  # more than 1D array?
        args = ma.array(args[0], copy=True)
        if len(args) == 2:
            x = args[0]
            y = args[1]
        else:
            x = args[:,0]
            y = args[:,1]
    else:
        x = ma.array(args[0]).flatten()
        y = ma.array(args[1]).flatten()
    m = ma.mask_or(ma.getmask(x), ma.getmask(y))
    if m is not nomask:
        x = ma.array(x,mask=m)
        y = ma.array(y,mask=m)
    n = len(x)
    (xmean, ymean) = (x.mean(), y.mean())
    (xm, ym) = (x-xmean, y-ymean)
    (Sxx, Syy) = (ma.add.reduce(xm*xm), ma.add.reduce(ym*ym))
    Sxy = ma.add.reduce(xm*ym)
    r_den = ma.sqrt(Sxx*Syy)
    if r_den == 0.0:
        r = 0.0
    else:
        r = Sxy / r_den
        if (r > 1.0):
            r = 1.0  # from numerical error
    # z = 0.5*log((1.0+r+TINY)/(1.0-r+TINY))
    df = n-2
    t = r * ma.sqrt(df/(1.0-r*r))
    prob = betai(0.5*df,0.5,df/(df+t*t))
    slope = Sxy / Sxx
    intercept = ymean - slope*xmean
    sterrest = ma.sqrt(1.-r*r) * y.std()
    return slope, intercept, r, prob, sterrest 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:38,代码来源:mstats_basic.py

示例7: pointbiserialr

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import mask_or [as 别名]
def pointbiserialr(x, y):
    """Calculates a point biserial correlation coefficient and its p-value.

    Parameters
    ----------
    x : array_like of bools
        Input array.
    y : array_like
        Input array.

    Returns
    -------
    correlation : float
        R value
    pvalue : float
        2-tailed p-value

    Notes
    -----
    Missing values are considered pair-wise: if a value is missing in x,
    the corresponding value in y is masked.

    For more details on `pointbiserialr`, see `stats.pointbiserialr`.

    """
    x = ma.fix_invalid(x, copy=True).astype(bool)
    y = ma.fix_invalid(y, copy=True).astype(float)
    # Get rid of the missing data
    m = ma.mask_or(ma.getmask(x), ma.getmask(y))
    if m is not nomask:
        unmask = np.logical_not(m)
        x = x[unmask]
        y = y[unmask]

    n = len(x)
    # phat is the fraction of x values that are True
    phat = x.sum() / float(n)
    y0 = y[~x]  # y-values where x is False
    y1 = y[x]  # y-values where x is True
    y0m = y0.mean()
    y1m = y1.mean()

    rpb = (y1m - y0m)*np.sqrt(phat * (1-phat)) / y.std()

    df = n-2
    t = rpb*ma.sqrt(df/(1.0-rpb**2))
    prob = _betai(0.5*df, 0.5, df/(df+t*t))

    return PointbiserialrResult(rpb, prob) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:51,代码来源:mstats_basic.py

示例8: theilslopes

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import mask_or [as 别名]
def theilslopes(y, x=None, alpha=0.95):
    r"""
    Computes the Theil-Sen estimator for a set of points (x, y).

    `theilslopes` implements a method for robust linear regression.  It
    computes the slope as the median of all slopes between paired values.

    Parameters
    ----------
    y : array_like
        Dependent variable.
    x : array_like or None, optional
        Independent variable. If None, use ``arange(len(y))`` instead.
    alpha : float, optional
        Confidence degree between 0 and 1. Default is 95% confidence.
        Note that `alpha` is symmetric around 0.5, i.e. both 0.1 and 0.9 are
        interpreted as "find the 90% confidence interval".

    Returns
    -------
    medslope : float
        Theil slope.
    medintercept : float
        Intercept of the Theil line, as ``median(y) - medslope*median(x)``.
    lo_slope : float
        Lower bound of the confidence interval on `medslope`.
    up_slope : float
        Upper bound of the confidence interval on `medslope`.

    Notes
    -----
    For more details on `theilslopes`, see `stats.theilslopes`.

    """
    y = ma.asarray(y).flatten()
    if x is None:
        x = ma.arange(len(y), dtype=float)
    else:
        x = ma.asarray(x).flatten()
        if len(x) != len(y):
            raise ValueError("Incompatible lengths ! (%s<>%s)" % (len(y),len(x)))

    m = ma.mask_or(ma.getmask(x), ma.getmask(y))
    y._mask = x._mask = m
    # Disregard any masked elements of x or y
    y = y.compressed()
    x = x.compressed().astype(float)
    # We now have unmasked arrays so can use `stats.theilslopes`
    return stats_theilslopes(y, x, alpha=alpha) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:51,代码来源:mstats_basic.py

示例9: theilslopes

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import mask_or [as 别名]
def theilslopes(y, x=None, alpha=0.05):
    """
    Computes the Theil slope as the median of all slopes between paired values.

    Parameters
    ----------
    y : array_like
        Dependent variable.
    x : {None, array_like}, optional
        Independent variable. If None, use arange(len(y)) instead.
    alpha : float
        Confidence degree.

    Returns
    -------
    medslope : float
        Theil slope
    medintercept : float
        Intercept of the Theil line, as median(y)-medslope*median(x)
    lo_slope : float
        Lower bound of the confidence interval on medslope
    up_slope : float
        Upper bound of the confidence interval on medslope

    """
    y = ma.asarray(y).flatten()
    y[-1] = masked
    n = len(y)
    if x is None:
        x = ma.arange(len(y), dtype=float)
    else:
        x = ma.asarray(x).flatten()
        if len(x) != n:
            raise ValueError("Incompatible lengths ! (%s<>%s)" % (n,len(x)))
    m = ma.mask_or(ma.getmask(x), ma.getmask(y))
    y._mask = x._mask = m
    ny = y.count()
    #
    slopes = ma.hstack([(y[i+1:]-y[i])/(x[i+1:]-x[i]) for i in range(n-1)])
    slopes.sort()
    medslope = ma.median(slopes)
    medinter = ma.median(y) - medslope*ma.median(x)
    #
    if alpha > 0.5:
        alpha = 1.-alpha
    z = stats.distributions.norm.ppf(alpha/2.)
    #
    (xties, yties) = (count_tied_groups(x), count_tied_groups(y))
    nt = ny*(ny-1)/2.
    sigsq = (ny*(ny-1)*(2*ny+5)/18.)
    sigsq -= np.sum(v*k*(k-1)*(2*k+5) for (k,v) in iteritems(xties))
    sigsq -= np.sum(v*k*(k-1)*(2*k+5) for (k,v) in iteritems(yties))
    sigma = np.sqrt(sigsq)

    Ru = min(np.round((nt - z*sigma)/2. + 1), len(slopes)-1)
    Rl = max(np.round((nt + z*sigma)/2.), 0)
    delta = slopes[[Rl,Ru]]
    return medslope, medinter, delta[0], delta[1] 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:60,代码来源:mstats_basic.py


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