- TensorFlow 2.0 Quick Start Guide
- Tony Holdroyd
- 65字
- 2021-06-24 16:02:04
Casting a tensor to another (tensor) datatype
TensorFlow variables of one type may be cast (coerced) to another type. More details may be found at https://www.tensorflow.org/api_docs/python/tf/cast.
Take the following example:
i = tf.cast(t1, dtype=tf.int32) # 42
i
The output will be as follows:
<tf.Tensor: id=116, shape=(), dtype=int32, numpy=42>
With truncation, it would be as follows:
j = tf.cast(tf.constant(4.9), dtype=tf.int32) # 4
j
The output will be as follows:
<tf.Tensor: id=119, shape=(), dtype=int32, numpy=4>
推薦閱讀
- 集成架構中型系統(tǒng)
- Linux Mint System Administrator’s Beginner's Guide
- 反饋系統(tǒng):多學科視角(原書第2版)
- Cloud Analytics with Microsoft Azure
- 21天學通Visual Basic
- Java Web整合開發(fā)全程指南
- 軟件構件技術
- 統(tǒng)計挖掘與機器學習:大數(shù)據(jù)預測建模和分析技術(原書第3版)
- Windows安全指南
- 數(shù)字多媒體技術基礎
- Building Google Cloud Platform Solutions
- ADuC系列ARM器件應用技術
- 30天學通Java Web項目案例開發(fā)
- 精通ROS機器人編程(原書第2版)
- Learning iOS 8 for Enterprise