Tensorflow中张量数据类型的转换

https://blog.csdn.net/Tramac/article/details/74942587

字符串转为数字:
tf.string_to_number
(string_tensor, out_type=None, name=None)
  • 1
  • 2
  • 3
转为64位浮点类型–float64:
tf.to_double(x, name=’ToDouble’)
  • 1
  • 2
转为32位浮点类型–float32:
tf.to_float(x, name=’ToFloat’)
  • 1
  • 2
转为32位整型–int32:
tf.to_int32(x, name=’ToInt32’)
  • 1
  • 2
转为64位整型–int64:
tf.to_int64(x, name=’ToInt64’)
  • 1
  • 2
将x或者x.values转换为dtype
# tensor a is [1.8, 2.2], dtype=tf.float
# tf.cast(a, tf.int32) ==> [1, 2],dtype=tf.int32
tf.cast(x, dtype, name=None)
原文地址:https://www.cnblogs.com/DjangoBlog/p/9487283.html