tf.cast()数据类型转换
代码 dtype=uint8转dtype=float32
print(x_)
x_float = tf.cast(x_ tf.float32)
print(x_float)
Tensor("preprocess/Reshape:0", shape=(?, 784), dtype=uint8)
Tensor("preprocess/Cast:0", shape=(?, 784), dtype=float32)
解析 x_float = tf.cast(x_, tf.float32)
x_ 张量,转换前数据
tf.float32 转换后数据类型
np.prod() 所有元素相乘
代码
np.prod([1, 2, 3, 4 ])
24
本文详细讲解了在TensorFlow中如何使用tf.cast()函数进行数据类型的转换,从uint8转换到float32,并展示了转换前后张量的数据类型变化。此外,还介绍了np.prod()函数的使用方法,用于计算数组中所有元素的乘积。

1112

被折叠的 条评论
为什么被折叠?



