(numerator, denominator)
return tf.where(denominator_is_zero, zeros, numerator / denominator)
Safe division, return 0 if denominator is 0
Safe division, return 0 if denominator is 0
Safe division return 0 if denominator is 0
def safe_div(numerator, denominator):
    """Safe division, return 0 if denominator is 0"""
    numerator, denominator = tf.to_float(numerator), tf.to_float(denominator)
    zeros = tf.zeros_like(numerator, dtype=numerator.dtype)
    denominator_is_zero = tf.equal(denominator, zeros)
    return tf.where(denominator_is_zero, zeros, numerator / denominator)
def safe_div ( numerator , denominator ) : numerator , denominator = tf . to_float ( numerator ) , tf . to_float ( denominator ) zeros = tf . zeros_like ( numerator , dtype = numerator . dtype ) denominator_is_zero = tf . equal ( denominator , zeros ) return tf . where ( denominator_is_zero , zeros , numerator / denominator )