operations.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:blmath 作者: bodylabs 项目源码 文件源码
def zero_safe_divide(a, b, default_error_value=0.):
    """Element-wise division that accounts for floating point errors.

    Both invalid floating-point (e.g. 0. / 0.) and divide be zero errors are
    suppressed. Resulting values (NaN and Inf respectively) are replaced with
    `default_error_value`.

    """
    import numpy as np

    with np.errstate(invalid='ignore', divide='ignore'):
        quotient = np.true_divide(a, b)
        bad_value_indices = np.logical_or(
            np.isnan(quotient), np.isinf(quotient))
        quotient[bad_value_indices] = default_error_value

    return quotient
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号