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