简介
在tensorflow中可以使用tf.cast()对tensor变量的类型进行转换.使用tf.reduce_min和tf.reduce_max可以计算张量上元素的最大值和最小值.
实现
import tensorflow as tf
x1 = tf.constant([1., 2., 3.], dtype = tf.float64)
print("x1: ", x1)
x2 = tf.cast(x1, tf.int32)
print("x2: ", x2)
print("minimum of x2: ", tf.reduce_min(x2))
print("maxmum of x2: ", tf.reduce_max(x2))