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)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM