1,tf.round
四舍五入取偶
小数部分小于0.5,则舍去;
小数部分大于0.5(注:0.5...x 也是大于0.5的),则进位;
小数部分恰好为0.5,取其最靠近的整数。
with tf.Session() as ss:
x = tf.constant([0.9, 2.5, 2.3, 1.5, 0.6, 0.51, 0.5, 0.46, -0.5, -4.5])
RX = tf.round(x) # [ 1.0, 2.0, 2.0, 2.0, -4.0 ]
rx2=tf.rint(x, name=None)
print(RX)
print(ss.run(RX))
print(ss.run(rx2))
2,tf.ceil
tf.ceil(x, name=None) # 向上取整
向上取整
3,tf.floor
向下取整
tf.floor(x, name=None) # 向下取整
4,tf.rint
与tf.round一样,四舍五入取偶
tf.rint(x, name=None) # 取最接近的整数