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


Python ma.MaskedArray方法代码示例

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


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

示例1: get_size

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def get_size(item):
    """Return size of an item of arbitrary type"""
    if isinstance(item, (list, set, tuple, dict)):
        return len(item)
    elif isinstance(item, (ndarray, MaskedArray)):
        return item.shape
    elif isinstance(item, Image):
        return item.size
    if isinstance(item, (DataFrame, Index, Series)):
        try:
            return item.shape
        except RecursionError:
            # This is necessary to avoid an error when trying to
            # get the shape of these objects.
            # Fixes spyder-ide/spyder-kernels#217
            return (-1, -1)
    else:
        return 1 
开发者ID:spyder-ide,项目名称:spyder-kernels,代码行数:20,代码来源:nsview.py

示例2: get_human_readable_type

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def get_human_readable_type(item):
    """Return human-readable type string of an item"""
    if isinstance(item, (ndarray, MaskedArray)):
        return u'Array of ' + item.dtype.name
    elif isinstance(item, Image):
        return "Image"
    else:
        text = get_type_string(item)
        if text is None:
            text = to_text_string('Unknown')
        else:
            return text[text.find('.')+1:]


#==============================================================================
# Globals filter: filter namespace dictionaries (to be edited in
# CollectionsEditor)
#============================================================================== 
开发者ID:spyder-ide,项目名称:spyder-kernels,代码行数:20,代码来源:nsview.py

示例3: transform_non_affine

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def transform_non_affine(self, points):
        if self._x.is_affine and self._y.is_affine:
            return points
        x = self._x
        y = self._y

        if x == y and x.input_dims == 2:
            return x.transform_non_affine(points)

        if x.input_dims == 2:
            x_points = x.transform_non_affine(points)[:, 0:1]
        else:
            x_points = x.transform_non_affine(points[:, 0])
            x_points = x_points.reshape((len(x_points), 1))

        if y.input_dims == 2:
            y_points = y.transform_non_affine(points)[:, 1:]
        else:
            y_points = y.transform_non_affine(points[:, 1])
            y_points = y_points.reshape((len(y_points), 1))

        if isinstance(x_points, MaskedArray) or isinstance(y_points, MaskedArray):
            return ma.concatenate((x_points, y_points), 1)
        else:
            return np.concatenate((x_points, y_points), 1) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:transforms.py

示例4: view_field

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def view_field(self, name, type=None):
        """construct a view of one data field
        
        Parameters
        ----------
        name : string
            the name of the field
        type : type, optional
            the type of the returned array
        
        Returns
        -------
        view : MaskedArray
            a view of the specified field
        """
        view = self.data[name]
        
        if type is not None:
            return view.view(type=type)
        else:
            return view 
开发者ID:vicariousinc,项目名称:pixelworld,代码行数:23,代码来源:datatypes.py

示例5: hdmedian

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def hdmedian(data, axis=-1, var=False):
    """
    Returns the Harrell-Davis estimate of the median along the given axis.

    Parameters
    ----------
    data : ndarray
        Data array.
    axis : int, optional
        Axis along which to compute the quantiles. If None, use a flattened
        array.
    var : bool, optional
        Whether to return the variance of the estimate.

    Returns
    -------
    hdmedian : MaskedArray
        The median values.  If ``var=True``, the variance is returned inside
        the masked array.  E.g. for a 1-D array the shape change from (1,) to
        (2,).

    """
    result = hdquantiles(data,[0.5], axis=axis, var=var)
    return result.squeeze() 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:26,代码来源:mstats_extras.py

示例6: test_1D

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def test_1D(self):
        a = (1,2,3,4)
        actual = mstats.gmean(a)
        desired = np.power(1*2*3*4,1./4.)
        assert_almost_equal(actual, desired, decimal=14)

        desired1 = mstats.gmean(a,axis=-1)
        assert_almost_equal(actual, desired1, decimal=14)
        assert_(not isinstance(desired1, ma.MaskedArray))

        a = ma.array((1,2,3,4),mask=(0,0,0,1))
        actual = mstats.gmean(a)
        desired = np.power(1*2*3,1./3.)
        assert_almost_equal(actual, desired,decimal=14)

        desired1 = mstats.gmean(a,axis=-1)
        assert_almost_equal(actual, desired1, decimal=14) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:19,代码来源:test_mstats_basic.py

示例7: createFromMaskedArray

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def createFromMaskedArray(cls, masked_arr):
        """ Creates an ArrayWithMak

            :param masked_arr: a numpy MaskedArray or numpy array
            :return: ArrayWithMask
        """
        if isinstance(masked_arr, ArrayWithMask):
            return masked_arr

        check_class(masked_arr, (np.ndarray, ma.MaskedArray))

        # A MaskedConstant (i.e. masked) is a special case of MaskedArray. It does not seem to have
        # a fill_value so we use None to use the default.
        # https://docs.scipy.org/doc/numpy/reference/maskedarray.baseclass.html#numpy.ma.masked
        fill_value = getattr(masked_arr, 'fill_value', None)

        return cls(masked_arr.data, masked_arr.mask, fill_value) 
开发者ID:titusjan,项目名称:argos,代码行数:19,代码来源:masks.py

示例8: fillValuesToNan

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def fillValuesToNan(masked_array):
    """ Replaces the fill_values of the masked array by NaNs

        If the array is None or it does not contain floating point values, it cannot contain NaNs.
        In that case the original array is returned.
    """
    if masked_array is not None and masked_array.dtype.kind == 'f':
        check_class(masked_array, ma.masked_array)
        logger.debug("Replacing fill_values by NaNs")
        masked_array[:] = ma.filled(masked_array, np.nan)
        masked_array.set_fill_value(np.nan)
    else:
        return masked_array


#TODO: does recordMask help here?
# https://docs.scipy.org/doc/numpy/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray.recordmask 
开发者ID:titusjan,项目名称:argos,代码行数:19,代码来源:masks.py

示例9: _fix_output

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def _fix_output(output, usemask=True, asrecarray=False):
    """
    Private function: return a recarray, a ndarray, a MaskedArray
    or a MaskedRecords depending on the input parameters
    """
    if not isinstance(output, MaskedArray):
        usemask = False
    if usemask:
        if asrecarray:
            output = output.view(MaskedRecords)
    else:
        output = ma.filled(output)
        if asrecarray:
            output = output.view(recarray)
    return output 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:recfunctions.py

示例10: test_join_subdtype

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def test_join_subdtype(self):
        # tests the bug in https://stackoverflow.com/q/44769632/102441
        from numpy.lib import recfunctions as rfn
        foo = np.array([(1,)],
                       dtype=[('key', int)])
        bar = np.array([(1, np.array([1,2,3]))],
                       dtype=[('key', int), ('value', 'uint16', 3)])
        res = join_by('key', foo, bar)
        assert_equal(res, bar.view(ma.MaskedArray)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_recfunctions.py

示例11: test_view_simple_dtype

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def test_view_simple_dtype(self):
        (mrec, a, b, arr) = self.data
        ntype = (float, 2)
        test = mrec.view(ntype)
        assert_(isinstance(test, ma.MaskedArray))
        assert_equal(test, np.array(list(zip(a, b)), dtype=float))
        assert_(test[3, 1] is ma.masked) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_mrecords.py

示例12: argstoarray

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def argstoarray(*args):
    """
    Constructs a 2D array from a group of sequences.

    Sequences are filled with missing values to match the length of the longest
    sequence.

    Parameters
    ----------
    args : sequences
        Group of sequences.

    Returns
    -------
    argstoarray : MaskedArray
        A ( `m` x `n` ) masked array, where `m` is the number of arguments and
        `n` the length of the longest argument.

    Notes
    -----
    `numpy.ma.row_stack` has identical behavior, but is called with a sequence
    of sequences.

    """
    if len(args) == 1 and not isinstance(args[0], ndarray):
        output = ma.asarray(args[0])
        if output.ndim != 2:
            raise ValueError("The input should be 2D")
    else:
        n = len(args)
        m = max([len(k) for k in args])
        output = ma.array(np.empty((n,m), dtype=float), mask=True)
        for (k,v) in enumerate(args):
            output[k,:len(v)] = v

    output[np.logical_not(np.isfinite(output._data))] = masked
    return output 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:39,代码来源:mstats_basic.py

示例13: idealfourths

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def idealfourths(data, axis=None):
    """
    Returns an estimate of the lower and upper quartiles.

    Uses the ideal fourths algorithm.

    Parameters
    ----------
    data : array_like
        Input array.
    axis : int, optional
        Axis along which the quartiles are estimated. If None, the arrays are
        flattened.

    Returns
    -------
    idealfourths : {list of floats, masked array}
        Returns the two internal values that divide `data` into four parts
        using the ideal fourths algorithm either along the flattened array
        (if `axis` is None) or along `axis` of `data`.

    """
    def _idf(data):
        x = data.compressed()
        n = len(x)
        if n < 3:
            return [np.nan,np.nan]
        (j,h) = divmod(n/4. + 5/12.,1)
        j = int(j)
        qlo = (1-h)*x[j-1] + h*x[j]
        k = n - j
        qup = (1-h)*x[k] + h*x[k-1]
        return [qlo, qup]
    data = ma.sort(data, axis=axis).view(MaskedArray)
    if (axis is None):
        return _idf(data)
    else:
        return ma.apply_along_axis(_idf, axis, data) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:40,代码来源:mstats_extras.py

示例14: test_view_simple_dtype

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def test_view_simple_dtype(self):
        (mrec, a, b, arr) = self.data
        ntype = (np.float, 2)
        test = mrec.view(ntype)
        self.assertTrue(isinstance(test, ma.MaskedArray))
        assert_equal(test, np.array(list(zip(a, b)), dtype=np.float))
        self.assertTrue(test[3, 1] is ma.masked) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:test_mrecords.py

示例15: is_known_type

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import MaskedArray [as 别名]
def is_known_type(item):
    """Return True if object has a known type"""
    # Unfortunately, the masked array case is specific
    return isinstance(item, MaskedArray) or get_type_string(item) is not None 
开发者ID:spyder-ide,项目名称:spyder-kernels,代码行数:6,代码来源:nsview.py


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