def divide_safezero(a, b):
'''
Divies a by b, then turns nans and infs into 0, so all division by 0
becomes 0.
Args:
a (np.ndarray)
b (np.ndarray|int|float)
Returns:
np.ndarray
'''
# deal with divide-by-zero: turn x/0 (inf) into 0, and turn 0/0 (nan) into
# 0.
c = a / b
c[c == np.inf] = 0.0
c = np.nan_to_num(c)
return c
# Classes
# -----------------------------------------------------------------------------
评论列表
文章目录