當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。