tf.cast()类型转换函数

版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/weixin_38314865/article/details/84769992
tf.cast(x, dtype, name=None)

参数

  • x:输入
  • dtype:转换目标类型
  • name:名称

返回:Tensor

例子:

import tensorflow as tf

a = [1,0,1,0]
b = [1,2,3,4]
c = [True, True, False]
d = tf.cast(a, dtype=bool)
e = tf.cast(b, dtype=bool)
f = tf.cast(c, dtype=tf.float32)
sess = tf.InteractiveSession()
print(sess.run(d))  # [ True False  True False]
print(sess.run(e))  # [ True  True  True  True]
print(sess.run(f))  # [1. 1. 0.]

猜你喜欢

转载自blog.csdn.net/weixin_38314865/article/details/84769992