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


Python ma.max方法代码示例

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


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

示例1: rgb_to_hsv

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def rgb_to_hsv(arr):
    """
    convert rgb values in a numpy array to hsv values
    input and output arrays should have shape (M,N,3)
    """
    out = np.zeros(arr.shape, dtype=np.float)
    arr_max = arr.max(-1)
    ipos = arr_max > 0
    delta = arr.ptp(-1)
    s = np.zeros_like(delta)
    s[ipos] = delta[ipos] / arr_max[ipos]
    ipos = delta > 0
    # red is max
    idx = (arr[:, :, 0] == arr_max) & ipos
    out[idx, 0] = (arr[idx, 1] - arr[idx, 2]) / delta[idx]
    # green is max
    idx = (arr[:, :, 1] == arr_max) & ipos
    out[idx, 0] = 2. + (arr[idx, 2] - arr[idx, 0]) / delta[idx]
    # blue is max
    idx = (arr[:, :, 2] == arr_max) & ipos
    out[idx, 0] = 4. + (arr[idx, 0] - arr[idx, 1]) / delta[idx]
    out[:, :, 0] = (out[:, :, 0] / 6.0) % 1.0
    out[:, :, 1] = s
    out[:, :, 2] = arr_max
    return out 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:colors.py

示例2: shade

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def shade(self, data, cmap, norm=None):
        """
        Take the input data array, convert to HSV values in the
        given colormap, then adjust those color values
        to give the impression of a shaded relief map with a
        specified light source.
        RGBA values are returned, which can then be used to
        plot the shaded image with imshow.
        """

        if norm is None:
            norm = Normalize(vmin=data.min(), vmax=data.max())

        rgb0 = cmap(norm(data))
        rgb1 = self.shade_rgb(rgb0, elevation=data)
        rgb0[:, :, 0:3] = rgb1
        return rgb0 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:19,代码来源:colors.py

示例3: regridToCoarse

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def regridToCoarse(fine,fac,mode,missValue):
    nr,nc = np.shape(fine)
    coarse = np.zeros(nr/fac * nc / fac).reshape(nr/fac,nc/fac) + MV
    nr,nc = np.shape(coarse)
    for r in range(0,nr):
        for c in range(0,nc):
            ar = fine[r * fac : fac * (r+1),c * fac: fac * (c+1)]
            m = np.ma.masked_values(ar,missValue)
            if ma.count(m) == 0:
                coarse[r,c] = MV
            else:
                if mode == 'average':
                    coarse [r,c] = ma.average(m)
                elif mode == 'median': 
                    coarse [r,c] = ma.median(m)
                elif mode == 'sum':
                    coarse [r,c] = ma.sum(m)
                elif mode =='min':
                    coarse [r,c] = ma.min(m)
                elif mode == 'max':
                    coarse [r,c] = ma.max(m)
    return coarse 
开发者ID:UU-Hydro,项目名称:PCR-GLOBWB_model,代码行数:24,代码来源:virtualOS.py

示例4: _contour_args

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def _contour_args(self, args, kwargs):
        if self.filled:
            fn = 'contourf'
        else:
            fn = 'contour'
        Nargs = len(args)
        if Nargs <= 2:
            z = ma.asarray(args[0], dtype=np.float64)
            x, y = self._initialize_x_y(z)
            args = args[1:]
        elif Nargs <= 4:
            x, y, z = self._check_xyz(args[:3], kwargs)
            args = args[3:]
        else:
            raise TypeError("Too many arguments to %s; see help(%s)" %
                            (fn, fn))
        z = ma.masked_invalid(z, copy=False)
        self.zmax = float(z.max())
        self.zmin = float(z.min())
        if self.logscale and self.zmin <= 0:
            z = ma.masked_where(z <= 0, z)
            warnings.warn('Log scale: values of z <= 0 have been masked')
            self.zmin = float(z.min())
        self._contour_level_args(z, args)
        return (x, y, z) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:27,代码来源:contour.py

示例5: autoscale

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def autoscale(self, A):
        '''
        Set *vmin*, *vmax* to min, max of *A*.
        '''
        self.vmin = ma.min(A)
        self.vmax = ma.max(A) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:colors.py

示例6: autoscale_None

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def autoscale_None(self, A):
        ' autoscale only None-valued vmin or vmax'
        if self.vmin is None and np.size(A) > 0:
            self.vmin = ma.min(A)
        if self.vmax is None and np.size(A) > 0:
            self.vmax = ma.max(A) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:colors.py

示例7: shade

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def shade(self, data, cmap):
        """
        Take the input data array, convert to HSV values in the
        given colormap, then adjust those color values
        to given the impression of a shaded relief map with a
        specified light source.
        RGBA values are returned, which can then be used to
        plot the shaded image with imshow.
        """

        rgb0 = cmap((data - data.min()) / (data.max() - data.min()))
        rgb1 = self.shade_rgb(rgb0, elevation=data)
        rgb0[:, :, 0:3] = rgb1
        return rgb0 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:colors.py

示例8: autoscale

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def autoscale(self, A):
        """
        Set *vmin*, *vmax* to min, max of *A*.
        """
        self.vmin = ma.min(A)
        self.vmax = ma.max(A) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:8,代码来源:colors.py

示例9: _process_args

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def _process_args(self, *args, **kwargs):
        """
        Process *args* and *kwargs*; override in derived classes.

        Must set self.levels, self.zmin and self.zmax, and update axes
        limits.
        """
        self.levels = args[0]
        self.allsegs = args[1]
        self.allkinds = len(args) > 2 and args[2] or None
        self.zmax = np.max(self.levels)
        self.zmin = np.min(self.levels)
        self._auto = False

        # Check lengths of levels and allsegs.
        if self.filled:
            if len(self.allsegs) != len(self.levels) - 1:
                raise ValueError('must be one less number of segments as '
                                 'levels')
        else:
            if len(self.allsegs) != len(self.levels):
                raise ValueError('must be same number of segments as levels')

        # Check length of allkinds.
        if (self.allkinds is not None and
                len(self.allkinds) != len(self.allsegs)):
            raise ValueError('allkinds has different length to allsegs')

        # Determine x,y bounds and update axes data limits.
        flatseglist = [s for seg in self.allsegs for s in seg]
        points = np.concatenate(flatseglist, axis=0)
        self._mins = points.min(axis=0)
        self._maxs = points.max(axis=0)

        return kwargs 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:37,代码来源:contour.py

示例10: _process_levels

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def _process_levels(self):
        """
        Assign values to :attr:`layers` based on :attr:`levels`,
        adding extended layers as needed if contours are filled.

        For line contours, layers simply coincide with levels;
        a line is a thin layer.  No extended levels are needed
        with line contours.
        """
        # Make a private _levels to include extended regions; we
        # want to leave the original levels attribute unchanged.
        # (Colorbar needs this even for line contours.)
        self._levels = list(self.levels)

        if self.logscale:
            lower, upper = 1e-250, 1e250
        else:
            lower, upper = -1e250, 1e250

        if self.extend in ('both', 'min'):
            self._levels.insert(0, lower)
        if self.extend in ('both', 'max'):
            self._levels.append(upper)
        self._levels = np.asarray(self._levels)

        if not self.filled:
            self.layers = self.levels
            return

        # Layer values are mid-way between levels in screen space.
        if self.logscale:
            # Avoid overflow by taking sqrt before multiplying.
            self.layers = (np.sqrt(self._levels[:-1])
                           * np.sqrt(self._levels[1:]))
        else:
            self.layers = 0.5 * (self._levels[:-1] + self._levels[1:]) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:38,代码来源:contour.py

示例11: getValDivZero

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import max [as 别名]
def getValDivZero(x,y,y_lim=smallNumber,z_def= 0.):
  #-returns the result of a division that possibly involves a zero
  # denominator; in which case, a default value is substituted:
  # x/y= z in case y > y_lim,
  # x/y= z_def in case y <= y_lim, where y_lim -> 0.
  # z_def is set to zero if not otherwise specified
  return pcr.ifthenelse(y > y_lim,x/pcr.max(y_lim,y),z_def) 
开发者ID:UU-Hydro,项目名称:PCR-GLOBWB_model,代码行数:9,代码来源:virtualOS.py


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