tf.cast() 数据类型转换
import tensorflow as tf
t1 = tf.Variable([1,2,3,4,5]) # 生成张量
t1
<tf.Variable ‘Variable:0’ shape=(5,) dtype=int32, numpy=array([1, 2, 3, 4, 5])>
t2 = tf.cast(
t1, # 待转换张量
dtype=tf.float32 # 转换后数据类型
)
t2
<tf.Tensor: shape=(5,), dtype=float32, numpy=array([1., 2., 3., 4., 5.], dtype=float32)>