tf.round()达到指定的精度 [英] tf.round() to a specified precision

查看:475
本文介绍了tf.round()达到指定的精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tf.round(x) x的值四舍五入为整数值.

tf.round(x) rounds the values of x to integer values.

有没有办法舍入到小数点后3位?

Is there any way to round to, say, 3 decimal places instead?

推荐答案

如果您不冒险达到太高的数字,就可以轻松地做到这一点:

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

提及:x *乘数的值不应超过2 ^ 32.因此,使用上述方法,不应舍入太大的数字.

Mention: The value of x * multiplier should not exceed 2^32. So using the above method, should not rounds too high numbers.

这篇关于tf.round()达到指定的精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆