def fill_na(x, fillval=0): fill = tf.ones_like(x) * fillval return tf.where(tf.is_finite(x), x, fill)