本文整理汇总了Python中numpy.seterrcall方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.seterrcall方法的具体用法?Python numpy.seterrcall怎么用?Python numpy.seterrcall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.seterrcall方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __enter__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterrcall [as 别名]
def __enter__(self):
self.oldstate = seterr(**self.kwargs)
if self.call is not _Unspecified:
self.oldcall = seterrcall(self.call)
示例2: __exit__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterrcall [as 别名]
def __exit__(self, *exc_info):
seterr(**self.oldstate)
if self.call is not _Unspecified:
seterrcall(self.oldcall)
示例3: raw_qualities_to_histogram
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterrcall [as 别名]
def raw_qualities_to_histogram(qualities):
"""Approximate the distribution of base quality at each position in a read
using a pseudo 2d kernel density estimation
Generate cumulative distribution functions
Args:
qualities (list): raw count of all phred scores
Returns:
list: list of cumulative distribution functions. One cdf per base. The
list has the size of the read length
"""
logger = logging.getLogger(__name__)
# moved this in quality_bins_to_histogram to try parallelization
# quals = util.split_list([i for i in zip(*qualities)], n_parts=cpus)
cdfs_list = []
for q in qualities:
numpy_log_handler = np.seterrcall(util.nplog)
with np.errstate(under='ignore', divide='call'):
try:
kde = stats.gaussian_kde(q, bw_method=0.2 / np.std(q, ddof=1))
except np.linalg.linalg.LinAlgError as e:
# if np.std of array is 0, we modify the array slightly to be
# able to divide by ~ np.std
# this will print a FloatingPointError in DEBUG mode
# logger.debug('np.std of quality array is zero: %s' % e)
q = list(q)
q[-1] += 1
kde = stats.gaussian_kde(q, bw_method=0.2 / np.std(q, ddof=1))
kde = kde.evaluate(range(41))
cdf = np.cumsum(kde)
cdf = cdf / cdf[-1]
cdfs_list.append(cdf)
return cdfs_list
示例4: get_mirrors
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterrcall [as 别名]
def get_mirrors(coxeter_diagram):
"""
Given a Coxter diagram consists of integers/rationals that represent the angles between
the mirrors (a rational p means the angle is π/p), return a square matrix whose
rows are the normal vectors of the mirrors. This matrix is not unique, here we use a
lower triangle one to simplify the computations.
"""
# error handling function when the input coxeter matrix is invalid.
def err_handler(err_type, flag):
print("Invalid input Coxeter diagram. This diagram does not give a finite \
symmetry group of an uniform polytope. See \
https://en.wikipedia.org/wiki/Coxeter_group#Symmetry_groups_of_regular_polytopes \
for a complete list of valid Coxeter diagrams.")
sys.exit(1)
np.seterrcall(err_handler)
np.seterr(all="call")
coxeter_matrix = np.array(make_symmetry_matrix(coxeter_diagram)).astype(np.float)
C = -np.cos(np.pi / coxeter_matrix)
M = np.zeros_like(C)
n = len(M)
# the first normal vector is simply (1, 0, ...)
M[0, 0] = 1
# in the i-th row, the j-th entry can be computed via the (j, j) entry.
for i in range(1, n):
for j in range(i):
M[i, j] = (C[i, j] - np.dot(M[j, :j], M[i, :j])) / M[j, j]
# the (i, i) entry is used to normalize this vector
M[i, i] = np.sqrt(1 - np.dot(M[i, :i], M[i, :i]))
return M
示例5: __call__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterrcall [as 别名]
def __call__(self, decorated: Callable) -> Callable:
"""Decorate the function."""
@functools.wraps(decorated)
def wrapper(*args: Any, **kwargs: Any) -> Any:
"""Configure NumPy to detect numerical errors."""
detector = NumericalErrorDetector(self.error)
with np.errstate(divide='call', over='call', under='ignore', invalid='call'):
np.seterrcall(detector)
returned = decorated(*args, **kwargs)
if detector.detected is not None:
returned[-1].append(detector.detected)
return returned
return wrapper
示例6: catch_nans
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterrcall [as 别名]
def catch_nans():
np.seterr(invalid='call')
np.seterrcall(examine_nan)