tf.cast()
强制转换类型
参数:
tf.cast(
x,
dtype,
name=None
)
使用案例:
import tensorflow as tf
x = tf.constant([1.8, 2.2], dtype=tf.float32)
r = tf.cast(x, tf.int32)
sess = tf.Session()
print(sess.run(r)) # [1, 2], dtype=tf.int32
tf.cast()
强制转换类型
参数:
tf.cast(
x,
dtype,
name=None
)
使用案例:
import tensorflow as tf
x = tf.constant([1.8, 2.2], dtype=tf.float32)
r = tf.cast(x, tf.int32)
sess = tf.Session()
print(sess.run(r)) # [1, 2], dtype=tf.int32