tf.round() to a specified precision

吃可爱长大的小学妹 提交于 2019-12-10 14:23:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!