问题
tf.round(x) rounds the values of x
to integer values.
Is there any way to round to, say, 3 decimal places instead?
回答1:
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.
来源:https://stackoverflow.com/questions/46688610/tf-round-to-a-specified-precision