當前位置: 首頁>>代碼示例>>Python>>正文


Python numerictypes.typecodes方法代碼示例

本文整理匯總了Python中numpy.core.numerictypes.typecodes方法的典型用法代碼示例。如果您正苦於以下問題:Python numerictypes.typecodes方法的具體用法?Python numerictypes.typecodes怎麽用?Python numerictypes.typecodes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.core.numerictypes的用法示例。


在下文中一共展示了numerictypes.typecodes方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: default_fill_value

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def default_fill_value (obj):
    "Function to calculate default fill value for an object."
    if isinstance(obj, float):
        return default_real_fill_value
    elif isinstance(obj, int) or isinstance(obj, long):
        return default_integer_fill_value
    elif isinstance(obj, bytes):
        return default_character_fill_value
    elif isinstance(obj, complex):
        return default_complex_fill_value
    elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
        x = obj.dtype.char
        if x in typecodes['Float']:
            return default_real_fill_value
        if x in typecodes['Integer']:
            return default_integer_fill_value
        if x in typecodes['Complex']:
            return default_complex_fill_value
        if x in typecodes['Character']:
            return default_character_fill_value
        if x in typecodes['UnsignedInteger']:
            return umath.absolute(default_integer_fill_value)
        return default_object_fill_value
    else:
        return default_object_fill_value 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:27,代碼來源:ma.py

示例2: minimum_fill_value

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def minimum_fill_value (obj):
    "Function to calculate default fill value suitable for taking minima."
    if isinstance(obj, float):
        return numeric.inf
    elif isinstance(obj, int) or isinstance(obj, long):
        return _MAXINT
    elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
        x = obj.dtype.char
        if x in typecodes['Float']:
            return numeric.inf
        if x in typecodes['Integer']:
            return _MAXINT
        if x in typecodes['UnsignedInteger']:
            return _MAXINT
    else:
        raise TypeError('Unsuitable type for calculating minimum.') 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:ma.py

示例3: maximum_fill_value

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def maximum_fill_value (obj):
    "Function to calculate default fill value suitable for taking maxima."
    if isinstance(obj, float):
        return -inf
    elif isinstance(obj, int) or isinstance(obj, long):
        return -_MAXINT
    elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
        x = obj.dtype.char
        if x in typecodes['Float']:
            return -inf
        if x in typecodes['Integer']:
            return -_MAXINT
        if x in typecodes['UnsignedInteger']:
            return 0
    else:
        raise TypeError('Unsuitable type for calculating maximum.') 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:ma.py

示例4: power

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def power (a, b, third=None):
    "a**b"
    if third is not None:
        raise MAError("3-argument power not supported.")
    ma = getmask(a)
    mb = getmask(b)
    m = mask_or(ma, mb)
    fa = filled(a, 1)
    fb = filled(b, 1)
    if fb.dtype.char in typecodes["Integer"]:
        return masked_array(umath.power(fa, fb), m)
    md = make_mask(umath.less(fa, 0), flag=1)
    m = mask_or(m, md)
    if m is nomask:
        return masked_array(umath.power(fa, fb))
    else:
        fa = numeric.where(m, 1, fa)
        return masked_array(umath.power(fa, fb), m) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:20,代碼來源:ma.py

示例5: __init__

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def __init__(self, pyfunc, otypes=None, doc=None, excluded=None,
                 cache=False, signature=None):
        self.pyfunc = pyfunc
        self.cache = cache
        self.signature = signature
        self._ufunc = None    # Caching to improve default performance

        if doc is None:
            self.__doc__ = pyfunc.__doc__
        else:
            self.__doc__ = doc

        if isinstance(otypes, str):
            for char in otypes:
                if char not in typecodes['All']:
                    raise ValueError("Invalid otype specified: %s" % (char,))
        elif iterable(otypes):
            otypes = ''.join([_nx.dtype(x).char for x in otypes])
        elif otypes is not None:
            raise ValueError("Invalid otype specification")
        self.otypes = otypes

        # Excluded variable support
        if excluded is None:
            excluded = set()
        self.excluded = set(excluded)

        if signature is not None:
            self._in_and_out_core_dims = _parse_gufunc_signature(signature)
        else:
            self._in_and_out_core_dims = None 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:33,代碼來源:function_base.py

示例6: __init__

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def __init__(self, pyfunc, otypes='', doc=None, excluded=None,
                 cache=False):
        self.pyfunc = pyfunc
        self.cache = cache
        self._ufunc = None    # Caching to improve default performance

        if doc is None:
            self.__doc__ = pyfunc.__doc__
        else:
            self.__doc__ = doc

        if isinstance(otypes, str):
            self.otypes = otypes
            for char in self.otypes:
                if char not in typecodes['All']:
                    raise ValueError(
                        "Invalid otype specified: %s" % (char,))
        elif iterable(otypes):
            self.otypes = ''.join([_nx.dtype(x).char for x in otypes])
        else:
            raise ValueError(
                "Invalid otype specification")

        # Excluded variable support
        if excluded is None:
            excluded = set()
        self.excluded = set(excluded) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:29,代碼來源:function_base.py

示例7: __init__

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def __init__(self, pyfunc, otypes='', doc=None, excluded=None, cache=False):
        self.pyfunc = pyfunc
        self.cache = cache

        if doc is None:
            self.__doc__ = pyfunc.__doc__
        else:
            self.__doc__ = doc

        if isinstance(otypes, str):
            self.otypes = otypes
            for char in self.otypes:
                if char not in typecodes['All']:
                    raise ValueError("Invalid otype specified: %s" % (char,))
        elif iterable(otypes):
            self.otypes = ''.join([_nx.dtype(x).char for x in otypes])
        else:
            raise ValueError("Invalid otype specification")

        # Excluded variable support
        if excluded is None:
            excluded = set()
        self.excluded = set(excluded)

        if self.otypes and not self.excluded:
            self._ufunc = None      # Caching to improve default performance 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:28,代碼來源:function_base.py

示例8: __idiv__

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def __idiv__(self, other):
        "Divide self by other in place."
        t = self._data.dtype.char
        f = filled(other, 0)
        t1 = f.dtype.char
        if t == t1:
            pass
        elif t in typecodes['Integer']:
            if t1 in typecodes['Integer']:
                f = f.astype(t)
            else:
                raise TypeError('Incorrect type for in-place operation.')
        elif t in typecodes['Float']:
            if t1 in typecodes['Integer']:
                f = f.astype(t)
            elif t1 in typecodes['Float']:
                f = f.astype(t)
            else:
                raise TypeError('Incorrect type for in-place operation.')
        elif t in typecodes['Complex']:
            if t1 in typecodes['Integer']:
                f = f.astype(t)
            elif t1 in typecodes['Float']:
                f = f.astype(t)
            elif t1 in typecodes['Complex']:
                f = f.astype(t)
            else:
                raise TypeError('Incorrect type for in-place operation.')
        else:
            raise TypeError('Incorrect type for in-place operation.')
        mo = getmask(other)
        result = divide(self, masked_array(f, mask=mo))
        self._data = result.data
        dm = result.raw_mask()
        if dm is not self._mask:
            self._mask = dm
            self._shared_mask = 1
        return self 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:40,代碼來源:ma.py

示例9: __iadd__

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def __iadd__(self, other):
        "Add other to self in place."
        t = self._data.dtype.char
        f = filled(other, 0)
        t1 = f.dtype.char
        if t == t1:
            pass
        elif t in typecodes['Integer']:
            if t1 in typecodes['Integer']:
                f = f.astype(t)
            else:
                raise TypeError('Incorrect type for in-place operation.')
        elif t in typecodes['Float']:
            if t1 in typecodes['Integer']:
                f = f.astype(t)
            elif t1 in typecodes['Float']:
                f = f.astype(t)
            else:
                raise TypeError('Incorrect type for in-place operation.')
        elif t in typecodes['Complex']:
            if t1 in typecodes['Integer']:
                f = f.astype(t)
            elif t1 in typecodes['Float']:
                f = f.astype(t)
            elif t1 in typecodes['Complex']:
                f = f.astype(t)
            else:
                raise TypeError('Incorrect type for in-place operation.')
        else:
            raise TypeError('Incorrect type for in-place operation.')

        if self._mask is nomask:
            self._data += f
            m = getmask(other)
            self._mask = m
            self._shared_mask = m is not nomask
        else:
            result = add(self, masked_array(f, mask=getmask(other)))
            self._data = result.data
            self._mask = result.mask
            self._shared_mask = 1
        return self 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:44,代碼來源:ma.py

示例10: __isub__

# 需要導入模塊: from numpy.core import numerictypes [as 別名]
# 或者: from numpy.core.numerictypes import typecodes [as 別名]
def __isub__(self, other):
        "Subtract other from self in place."
        t = self._data.dtype.char
        f = filled(other, 0)
        t1 = f.dtype.char
        if t == t1:
            pass
        elif t in typecodes['Integer']:
            if t1 in typecodes['Integer']:
                f = f.astype(t)
            else:
                raise TypeError('Incorrect type for in-place operation.')
        elif t in typecodes['Float']:
            if t1 in typecodes['Integer']:
                f = f.astype(t)
            elif t1 in typecodes['Float']:
                f = f.astype(t)
            else:
                raise TypeError('Incorrect type for in-place operation.')
        elif t in typecodes['Complex']:
            if t1 in typecodes['Integer']:
                f = f.astype(t)
            elif t1 in typecodes['Float']:
                f = f.astype(t)
            elif t1 in typecodes['Complex']:
                f = f.astype(t)
            else:
                raise TypeError('Incorrect type for in-place operation.')
        else:
            raise TypeError('Incorrect type for in-place operation.')

        if self._mask is nomask:
            self._data -= f
            m = getmask(other)
            self._mask = m
            self._shared_mask = m is not nomask
        else:
            result = subtract(self, masked_array(f, mask=getmask(other)))
            self._data = result.data
            self._mask = result.mask
            self._shared_mask = 1
        return self 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:44,代碼來源:ma.py


注:本文中的numpy.core.numerictypes.typecodes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。