tf.cast

作者: Nise9s | 来源:发表于2018-04-09 16:16 被阅读0次
tf.cast(
    x,
    dtype,
    name=None
)

tf.cast可以改变tensor的数据类型。
x是我们要操作的tensor,而dtype是我们要将tensor变成的数据类型。
举例如下:

x = tf.constant([1.8, 2.2], dtype=tf.float32)
tf.cast(x, tf.int32)  # [1, 2], dtype=tf.int32

完成了将一个数据类型为float32得tensor变为int32
类型的tensor的操作。

相关文章

网友评论

      本文标题:tf.cast

      本文链接:https://www.haomeiwen.com/subject/mipihftx.html