本文整理汇总了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
示例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.')
示例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.')
示例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)
示例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
示例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)
示例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
示例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
示例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
示例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