tf.round(x)
rounds the values of x
to integer values.
Is there any way to round to, say, 3 decimal places instead?
Precision of a numeric value describes the number of digits that are used to express that value, including digits to both the left and the right of any decimal point. For example 4.520 has a precision of 4. Zuora supports up to 13 digits to the left of the decimal place, and up to 9 digits to the right.
Rounding is a fundamentally nondifferentiable function, so you're out of luck there.
You can do it easily like that, if you don't risk reaching too high numbers:
def my_tf_round(x, decimals = 0):
multiplier = tf.constant(10**decimals, dtype=x.dtype)
return tf.round(x * multiplier) / multiplier
Mention: The value of x * multiplier should not exceed 2^32. So using the above method, should not rounds too high numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With