本文整理匯總了Python中numpy.issubclass_方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.issubclass_方法的具體用法?Python numpy.issubclass_怎麽用?Python numpy.issubclass_使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.issubclass_方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubclass_ [as 別名]
def __init__(self, theta, phi, r, tt, tp, w=None, eps=1E-16):
if np.issubclass_(w, float):
w = ones(len(theta)) * w
nt_, np_ = 8 + len(tt), 8 + len(tp)
tt_, tp_ = zeros((nt_,), float), zeros((np_,), float)
tt_[4:-4], tp_[4:-4] = tt, tp
tt_[-4:], tp_[-4:] = np.pi, 2. * np.pi
tt_, tp_, c, fp, ier = dfitpack.spherfit_lsq(theta, phi, r, tt_, tp_,
w=w, eps=eps)
if ier < -2:
deficiency = 6 + (nt_ - 8) * (np_ - 7) + ier
message = _spherefit_messages.get(-3) % (deficiency, -ier)
warnings.warn(message)
elif ier not in [0, -1, -2]:
message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
raise ValueError(message)
self.fp = fp
self.tck = tt_, tp_, c
self.degrees = (3, 3)
示例2: __init__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubclass_ [as 別名]
def __init__(self, theta, phi, r, tt, tp, w=None, eps=1E-16):
if np.issubclass_(w, float):
w = ones(len(theta)) * w
nt_, np_ = 8 + len(tt), 8 + len(tp)
tt_, tp_ = zeros((nt_,), float), zeros((np_,), float)
tt_[4:-4], tp_[4:-4] = tt, tp
tt_[-4:], tp_[-4:] = np.pi, 2. * np.pi
tt_, tp_, c, fp, ier = dfitpack.spherfit_lsq(theta, phi, r, tt_, tp_,
w=w, eps=eps)
if ier < -2:
deficiency = 6 + (nt_ - 8) * (np_ - 7) + ier
message = _spherefit_messages.get(-3) % (deficiency, -ier)
warnings.warn(message)
elif not ier in [0, -1, -2]:
message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
raise ValueError(message)
self.fp = fp
self.tck = tt_, tp_, c
self.degrees = (3, 3)
示例3: __call__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubclass_ [as 別名]
def __call__(self, instance, attribute, value):
if isinstance(value, np.ndarray):
value_type = value.dtype
else:
value_type = type(value)
if self.dtype is not None and not np.issubdtype(value_type, self.dtype):
# TODO: add better error message
raise TypeError(
f"Attribute '{attribute.name}' of {instance.__class__} "
+ f"must have dtype {self.dtype}"
)
if self.subclass is not None and not np.issubclass_(
type(value), self.subclass
):
# TODO: add better error message
raise TypeError(
f"Attribute '{attribute.name}' of {instance.__class__} "
+ f"must be of subclass {self.subclass}"
)
示例4: type_to_builtin_type
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubclass_ [as 別名]
def type_to_builtin_type(type):
# Infer from numpy type if it is one
if type.__module__ == np.__name__:
return numpy_type_to_builtin_type(type)
# Otherwise, try to infer from a few generic python types
if np.issubclass_(type, bool):
return types_bool
elif np.issubclass_(type, six.integer_types):
return types_int32
elif np.issubclass_(type, six.string_types):
return types_str
elif np.issubclass_(type, float):
return types_fp32
else:
raise TypeError("Could not determine builtin type for " + str(type))
示例5: find_estimator
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubclass_ [as 別名]
def find_estimator(est):
"""Return estimator class.
Return an estimator class. If input is a class, check if it implements
methods 'estimate' and 'is_parallel' necessary for network analysis
(see abstract class 'Estimator' for documentation). If input is a string,
search for class with that name in IDTxl and return it.
Args:
est : str | Class
name of an estimator class implemented in IDTxl or custom estimator
class
Returns
Class
Estimator class
"""
if inspect.isclass(est):
# Test if provided class implements the Estimator class. This
# constraint may be relaxed in the future.
if not np.issubclass_(est, Estimator):
raise RuntimeError('Provided class should implement abstract class'
' Estimator.')
return est
elif type(est) is str:
module_list = _package_contents()
estimator = None
for m in module_list:
try:
module = importlib.import_module('.' + m, __package__)
return getattr(module, est)
except AttributeError:
pass
if not estimator:
raise RuntimeError('Estimator {0} not found.'.format(est))
else:
raise TypeError('Please provide an estimator class or the name of an '
'estimator as string.')
示例6: numpy_scalar_to_python
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubclass_ [as 別名]
def numpy_scalar_to_python(scalar):
"""
Converts a NumPy scalar to a regular python type.
"""
scalar_type = type(scalar)
if np.issubclass_(scalar_type, np.float_):
return float(scalar)
elif np.issubclass_(scalar_type, np.int_):
return int(scalar)
return scalar
示例7: numpy_type_to_builtin_type
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubclass_ [as 別名]
def numpy_type_to_builtin_type(nptype):
if type(nptype) == np.dtype:
nptype = nptype.type
if np.issubclass_(nptype, np.bool) or np.issubclass_(nptype, np.bool_):
# numpy as 2 bool types it looks like. what is the difference?
return types_bool
elif np.issubclass_(nptype, np.int8):
return types_int8
elif np.issubclass_(nptype, np.int16):
return types_int16
elif np.issubclass_(nptype, np.int32):
return types_int32
elif np.issubclass_(nptype, np.int64):
return types_int64
elif np.issubclass_(nptype, np.uint8):
return types_int8
elif np.issubclass_(nptype, np.uint16):
return types_int16
elif np.issubclass_(nptype, np.uint32):
return types_int32
elif np.issubclass_(nptype, np.uint64):
return types_int64
elif np.issubclass_(nptype, np.int):
# Catch all int
return types_int32
elif np.issubclass_(nptype, np.object_):
# symbolic shape is considered int32
return types_int32
elif np.issubclass_(nptype, np.float16):
return types_fp16
elif np.issubclass_(nptype, np.float32) or np.issubclass_(nptype, np.single):
return types_fp32
elif np.issubclass_(nptype, np.float64) or np.issubclass_(nptype, np.double):
return types_fp64
elif (
np.issubclass_(nptype, six.string_types)
or np.issubclass_(nptype, np.string_)
or np.issubclass_(nptype, np.str_)
):
return types_str
else:
raise TypeError("Unsupported numpy type: %s" % (nptype))
# Tries to get the equivalent builtin type of a
# numpy or python type.